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);
144 total += q * BLOCK_SIZE;
153 static int _pkginfo_get_author(sqlite3 *db, const char *pkgid,
156 static const char query_raw[] =
157 "SELECT author_name, author_email, author_href "
158 "FROM package_info WHERE package=%Q";
165 query = sqlite3_mprintf(query_raw, pkgid);
167 LOGE("out of memory");
168 return PMINFO_R_ERROR;
171 ret = sqlite3_prepare_v2(db, query, strlen(query),
174 if (ret != SQLITE_OK) {
175 LOGE("prepare failed: %s", sqlite3_errmsg(db));
176 return PMINFO_R_ERROR;
179 if (sqlite3_step(stmt) == SQLITE_ERROR) {
180 LOGE("step error: %s", sqlite3_errmsg(db));
181 sqlite3_finalize(stmt);
182 return PMINFO_R_ERROR;
185 /* one author per one package */
186 info = calloc(1, sizeof(author_x));
188 LOGE("out of memory");
189 sqlite3_finalize(stmt);
190 return PMINFO_R_ERROR;
193 _save_column_str(stmt, idx++, &info->text);
194 _save_column_str(stmt, idx++, &info->email);
195 _save_column_str(stmt, idx++, &info->href);
198 *author = g_list_append(*author, info);
200 sqlite3_finalize(stmt);
205 static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
206 const char *locale, GList **label)
208 static const char query_raw[] =
209 "SELECT package_label, package_locale "
210 "FROM package_localized_info "
211 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
218 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
220 LOGE("out of memory");
221 return PMINFO_R_ERROR;
224 ret = sqlite3_prepare_v2(db, query, strlen(query),
227 if (ret != SQLITE_OK) {
228 LOGE("prepare failed: %s", sqlite3_errmsg(db));
229 return PMINFO_R_ERROR;
232 while (sqlite3_step(stmt) == SQLITE_ROW) {
233 info = calloc(1, sizeof(label_x));
235 LOGE("out of memory");
236 sqlite3_finalize(stmt);
237 return PMINFO_R_ERROR;
240 _save_column_str(stmt, idx++, &info->text);
241 _save_column_str(stmt, idx++, &info->lang);
242 *label = g_list_append(*label, info);
245 sqlite3_finalize(stmt);
250 static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
253 static const char query_raw[] =
254 "SELECT package_icon, package_locale "
255 "FROM package_localized_info "
256 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
263 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
265 LOGE("out of memory");
266 return PMINFO_R_ERROR;
269 ret = sqlite3_prepare_v2(db, query, strlen(query),
272 if (ret != SQLITE_OK) {
273 LOGE("prepare failed: %s", sqlite3_errmsg(db));
274 return PMINFO_R_ERROR;
277 while (sqlite3_step(stmt) == SQLITE_ROW) {
278 info = calloc(1, sizeof(icon_x));
280 LOGE("out of memory");
281 sqlite3_finalize(stmt);
282 return PMINFO_R_ERROR;
285 _save_column_str(stmt, idx++, &info->text);
286 _save_column_str(stmt, idx++, &info->lang);
287 *icon = g_list_append(*icon, info);
290 sqlite3_finalize(stmt);
295 static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
296 const char *locale, GList **description)
298 static const char query_raw[] =
299 "SELECT package_description, package_locale "
300 "FROM package_localized_info "
301 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
308 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
310 LOGE("out of memory");
311 return PMINFO_R_ERROR;
314 ret = sqlite3_prepare_v2(db, query, strlen(query),
317 if (ret != SQLITE_OK) {
318 LOGE("prepare failed: %s", sqlite3_errmsg(db));
319 return PMINFO_R_ERROR;
322 while (sqlite3_step(stmt) == SQLITE_ROW) {
323 info = calloc(1, sizeof(description_x));
325 LOGE("out of memory");
326 sqlite3_finalize(stmt);
327 return PMINFO_R_ERROR;
330 _save_column_str(stmt, idx++, &info->text);
331 _save_column_str(stmt, idx++, &info->lang);
332 *description = g_list_append(*description, info);
335 sqlite3_finalize(stmt);
340 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
343 static const char query_raw[] =
344 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
350 query = sqlite3_mprintf(query_raw, pkgid);
352 LOGE("out of memory");
353 return PMINFO_R_ERROR;
356 ret = sqlite3_prepare_v2(db, query, strlen(query),
359 if (ret != SQLITE_OK) {
360 LOGE("prepare failed: %s", sqlite3_errmsg(db));
361 return PMINFO_R_ERROR;
364 while (sqlite3_step(stmt) == SQLITE_ROW) {
366 _save_column_str(stmt, 0, &privilege);
368 *privileges = g_list_append(*privileges,
369 (gpointer)privilege);
372 sqlite3_finalize(stmt);
377 static const char join_localized_info[] =
378 " LEFT OUTER JOIN package_localized_info"
379 " ON pi.package=package_localized_info.package"
380 " AND package_localized_info.package_locale=?";
381 static const char join_privilege_info[] =
382 " LEFT OUTER JOIN package_privilege_info"
383 " ON pi.package=package_privilege_info.package";
385 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
386 const char *locale, char **query, GList **bind_params)
389 char buf[MAX_QUERY_LEN] = { '\0' };
390 char buf2[MAX_QUERY_LEN] = { '\0' };
391 char *condition = NULL;
398 len += strlen(" WHERE 1=1 ");
399 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
400 for (list = filter->list; list; list = list->next) {
401 joined |= __get_filter_condition(list->data, &condition,
403 if (condition == NULL)
406 len += strlen(" AND ");
407 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
409 len += strlen(condition);
410 strncat(buf, condition, sizeof(buf) - len - 1);
415 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
416 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
417 len += strlen(join_localized_info);
418 *bind_params = g_list_append(*bind_params, strdup(locale));
420 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
421 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
422 len += strlen(join_privilege_info);
424 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
426 *query = strdup(buf2);
428 return PMINFO_R_ERROR;
433 static void __free_packages(gpointer data)
435 pkgmgrinfo_basic_free_package((package_x *)data);
438 static int __bind_params(sqlite3_stmt *stmt, GList *params)
440 GList *tmp_list = NULL;
444 if (stmt == NULL || params == NULL)
445 return PMINFO_R_EINVAL;
449 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
450 if (ret != SQLITE_OK)
451 return PMINFO_R_ERROR;
452 tmp_list = tmp_list->next;
458 static int _pkginfo_get_packages(uid_t uid, const char *locale,
459 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
461 static const char query_raw[] =
462 "SELECT DISTINCT pi.package, pi.package_version, "
463 "pi.install_location, pi.package_removable, "
464 "pi.package_preload, pi.package_readonly, pi.package_update, "
465 "pi.package_appsetting, pi.package_system, pi.package_type, "
466 "pi.package_size, pi.installed_time, pi.installed_storage, "
467 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
468 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
469 "pi.package_api_version, pi.package_support_disable, "
470 "pi.package_tep_name, pi.package_zip_mount_file "
471 "FROM package_info as pi ";
472 int ret = PMINFO_R_ERROR;
475 char *constraints = NULL;
476 char query[MAX_QUERY_LEN] = { '\0' };
477 package_x *info = NULL;
478 GList *bind_params = NULL;
481 pkgmgrinfo_filter_x *tmp_filter = NULL;
483 dbpath = getUserPkgParserDBPathUID(uid);
485 return PMINFO_R_ERROR;
487 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
488 if (ret != SQLITE_OK) {
489 _LOGD("failed to open db: %d", ret);
490 return PMINFO_R_ERROR;
493 if (filter != NULL) {
496 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
497 if (ret != PMINFO_R_OK) {
498 _LOGE("Failed to create filter");
499 return PMINFO_R_ERROR;
503 /* add package_disable='false' clause by default */
504 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
506 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
507 if (ret != PMINFO_R_OK) {
508 LOGE("Failed to get WHERE clause");
513 snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraints);
515 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
517 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
518 if (ret != SQLITE_OK) {
519 LOGE("prepare failed: %s", sqlite3_errmsg(db));
520 ret = PMINFO_R_ERROR;
524 ret = __bind_params(stmt, bind_params);
525 if (ret != SQLITE_OK) {
526 LOGE("Failed to bind parameters");
530 while (sqlite3_step(stmt) == SQLITE_ROW) {
531 info = calloc(1, sizeof(package_x));
533 LOGE("out of memory");
534 sqlite3_finalize(stmt);
535 sqlite3_close_v2(db);
536 return PMINFO_R_ERROR;
539 _save_column_str(stmt, idx++, &info->package);
540 if (g_hash_table_contains(packages,
541 (gconstpointer)info->package)) {
546 _save_column_str(stmt, idx++, &info->version);
547 _save_column_str(stmt, idx++, &info->installlocation);
548 _save_column_str(stmt, idx++, &info->removable);
549 _save_column_str(stmt, idx++, &info->preload);
550 _save_column_str(stmt, idx++, &info->readonly);
551 _save_column_str(stmt, idx++, &info->update);
552 _save_column_str(stmt, idx++, &info->appsetting);
553 _save_column_str(stmt, idx++, &info->system);
554 _save_column_str(stmt, idx++, &info->type);
555 _save_column_str(stmt, idx++, &info->package_size);
556 _save_column_str(stmt, idx++, &info->installed_time);
557 _save_column_str(stmt, idx++, &info->installed_storage);
558 _save_column_str(stmt, idx++, &info->storeclient_id);
559 _save_column_str(stmt, idx++, &info->mainapp_id);
560 _save_column_str(stmt, idx++, &info->package_url);
561 _save_column_str(stmt, idx++, &info->root_path);
562 _save_column_str(stmt, idx++, &info->csc_path);
563 _save_column_str(stmt, idx++, &info->nodisplay_setting);
564 _save_column_str(stmt, idx++, &info->api_version);
565 _save_column_str(stmt, idx++, &info->support_disable);
566 _save_column_str(stmt, idx++, &info->tep_name);
567 _save_column_str(stmt, idx++, &info->zip_mount_file);
568 info->for_all_users =
569 strdup((uid != GLOBAL_USER) ? "false" : "true");
571 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
572 if (_pkginfo_get_author(db, info->package,
574 pkgmgrinfo_basic_free_package(info);
575 sqlite3_finalize(stmt);
576 sqlite3_close_v2(db);
577 return PMINFO_R_ERROR;
581 if (flag & PMINFO_PKGINFO_GET_LABEL) {
582 if (_pkginfo_get_label(db, info->package, locale,
584 pkgmgrinfo_basic_free_package(info);
585 sqlite3_finalize(stmt);
586 sqlite3_close_v2(db);
587 return PMINFO_R_ERROR;
591 if (flag & PMINFO_PKGINFO_GET_ICON) {
592 if (_pkginfo_get_icon(db, info->package, locale,
594 pkgmgrinfo_basic_free_package(info);
595 sqlite3_finalize(stmt);
596 sqlite3_close_v2(db);
597 return PMINFO_R_ERROR;
601 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
602 if (_pkginfo_get_description(db, info->package, locale,
603 &info->description)) {
604 pkgmgrinfo_basic_free_package(info);
605 sqlite3_finalize(stmt);
606 sqlite3_close_v2(db);
607 return PMINFO_R_ERROR;
611 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
612 if (_pkginfo_get_privilege(db, info->package,
613 &info->privileges)) {
614 pkgmgrinfo_basic_free_package(info);
615 sqlite3_finalize(stmt);
616 sqlite3_close_v2(db);
617 return PMINFO_R_ERROR;
621 g_hash_table_insert(packages, (gpointer)info->package,
631 if (ret != PMINFO_R_OK && info != NULL)
632 pkgmgrinfo_basic_free_package(info);
635 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
637 g_list_free_full(bind_params, free);
638 sqlite3_close_v2(db);
639 sqlite3_finalize(stmt);
644 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
645 pkgmgrinfo_filter_x *filter, int flag,
646 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
651 pkgmgr_pkginfo_x info;
656 locale = _get_system_locale();
658 return PMINFO_R_ERROR;
660 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
664 return PMINFO_R_ERROR;
667 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
668 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
669 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
672 if (ret != PMINFO_R_OK) {
673 g_hash_table_destroy(list);
675 return PMINFO_R_ERROR;
678 g_hash_table_iter_init(&iter, list);
679 while (g_hash_table_iter_next(&iter, NULL, &value)) {
680 pkg = (package_x *)value;
683 info.locale = locale;
684 if (pkg_list_cb(&info, user_data) < 0)
688 g_hash_table_destroy(list);
694 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
695 pkgmgrinfo_pkginfo_h *handle)
700 pkgmgrinfo_pkginfo_filter_h filter;
701 pkgmgr_pkginfo_x *info;
703 if (pkgid == NULL || handle == NULL) {
704 LOGE("invalid parameter");
705 return PMINFO_R_EINVAL;
708 locale = _get_system_locale();
710 return PMINFO_R_ERROR;
712 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
713 if (ret != PMINFO_R_OK) {
718 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
719 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
720 if (ret != PMINFO_R_OK) {
721 pkgmgrinfo_pkginfo_filter_destroy(filter);
723 return PMINFO_R_ERROR;
726 list = g_hash_table_new(g_str_hash, g_str_equal);
728 pkgmgrinfo_pkginfo_filter_destroy(filter);
730 return PMINFO_R_ERROR;
733 ret = _pkginfo_get_packages(uid, locale, filter,
734 PMINFO_PKGINFO_GET_ALL, list);
735 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
736 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
737 PMINFO_PKGINFO_GET_ALL, list);
739 pkgmgrinfo_pkginfo_filter_destroy(filter);
740 if (ret != PMINFO_R_OK) {
741 g_hash_table_destroy(list);
746 if (!g_hash_table_size(list)) {
747 _LOGI("pkginfo for [%s] is not existed for user [%d]",
749 g_hash_table_destroy(list);
751 return PMINFO_R_ENOENT;
754 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
756 _LOGE("out of memory");
757 g_hash_table_destroy(list);
759 return PMINFO_R_ERROR;
763 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
764 info->locale = locale;
766 /* just free list only */
767 g_hash_table_destroy(list);
774 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
775 pkgmgrinfo_pkginfo_h *handle)
777 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
780 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
781 int flag, void *user_data, uid_t uid)
783 if (pkg_list_cb == NULL) {
784 LOGE("invalid parameter");
785 return PMINFO_R_EINVAL;
788 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
789 pkg_list_cb, user_data);
792 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
793 int flag, void *user_data)
795 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
796 user_data, _getuid());
799 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
800 void *user_data, uid_t uid)
802 if (pkg_list_cb == NULL) {
803 LOGE("invalid parameter");
804 return PMINFO_R_EINVAL;
807 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
808 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
811 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
814 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
818 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
820 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
822 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
823 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
825 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
826 return PMINFO_R_ERROR;
828 *pkg_name = (char *)info->pkg_info->package;
833 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
835 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
837 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
838 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
840 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
841 return PMINFO_R_ERROR;
843 *pkgid = (char *)info->pkg_info->package;
848 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
850 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
853 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
855 if (info->pkg_info == NULL)
856 return PMINFO_R_ERROR;
857 if (info->pkg_info->type == NULL)
858 info->pkg_info->type = strdup("");
860 *type = (char *)info->pkg_info->type;
865 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
867 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
869 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
870 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
872 if (info->pkg_info == NULL)
873 return PMINFO_R_ERROR;
874 if (info->pkg_info->version == NULL)
875 info->pkg_info->version = strdup("");
877 *version = (char *)info->pkg_info->version;
882 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
884 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
886 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
887 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
889 if (info->pkg_info == NULL)
890 return PMINFO_R_ERROR;
891 if (info->pkg_info->api_version == NULL)
892 info->pkg_info->api_version = strdup("");
894 *api_version = (char *)info->pkg_info->api_version;
899 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
901 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
903 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
904 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
906 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
907 return PMINFO_R_ERROR;
909 *tep_name = (char *)info->pkg_info->tep_name;
914 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
916 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
919 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
921 if (info->pkg_info == NULL)
922 return PMINFO_R_ERROR;
923 if (info->pkg_info->zip_mount_file == NULL)
924 info->pkg_info->zip_mount_file = strdup("");
926 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
931 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
934 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
936 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
937 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
939 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
940 return PMINFO_R_ERROR;
942 val = (char *)info->pkg_info->installlocation;
943 if (strcmp(val, "internal-only") == 0)
944 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
945 else if (strcmp(val, "prefer-external") == 0)
946 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
948 *location = PMINFO_INSTALL_LOCATION_AUTO;
953 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
955 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
959 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
961 if (info->pkg_info == NULL)
962 return PMINFO_R_ERROR;
964 if (info->pkg_info->package_size == NULL) {
967 _LOGE("out of memory");
968 return PMINFO_R_ERROR;
970 info->pkg_info->package_size = temp;
974 *size = atoi((char *)info->pkg_info->package_size);
979 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
984 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
986 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
987 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
989 locale = info->locale;
990 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
992 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
993 return PMINFO_R_ERROR;
995 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
996 ptr = (icon_x *)tmp->data;
997 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
998 strcmp(ptr->lang, locale))
1000 *icon = (char *)ptr->text;
1004 locale = DEFAULT_LOCALE;
1005 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1006 ptr = (icon_x *)tmp->data;
1007 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1008 strcmp(ptr->lang, locale))
1010 *icon = (char *)ptr->text;
1019 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1024 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1026 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1027 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1029 locale = info->locale;
1030 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1032 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1033 return PMINFO_R_ERROR;
1035 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1036 ptr = (label_x *)tmp->data;
1037 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1038 strcmp(ptr->lang, locale))
1040 *label = (char *)ptr->text;
1044 locale = DEFAULT_LOCALE;
1045 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1046 ptr = (label_x *)tmp->data;
1047 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1048 strcmp(ptr->lang, locale))
1050 *label = (char *)ptr->text;
1059 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1064 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1067 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1069 locale = info->locale;
1070 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1072 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1073 return PMINFO_R_ERROR;
1075 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1076 ptr = (description_x *)tmp->data;
1077 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1078 strcmp(ptr->lang, locale))
1080 *description = (char *)ptr->text;
1084 locale = DEFAULT_LOCALE;
1085 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1086 ptr = (description_x *)tmp->data;
1087 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1088 strcmp(ptr->lang, locale))
1090 *description = (char *)ptr->text;
1099 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1101 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1104 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1105 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1107 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1108 return PMINFO_R_ERROR;
1110 author = (author_x *)info->pkg_info->author->data;
1112 return PMINFO_R_ERROR;
1113 if (author->text == NULL)
1114 author->text = strdup("");
1116 *author_name = (char *)author->text;
1121 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1123 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1127 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1129 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1130 return PMINFO_R_ERROR;
1132 author = (author_x *)info->pkg_info->author->data;
1134 return PMINFO_R_ERROR;
1135 if (author->email == NULL)
1136 author->email = strdup("");
1138 *author_email = (char *)author->email;
1143 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1145 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1148 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1149 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1151 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1152 return PMINFO_R_ERROR;
1154 author = (author_x *)info->pkg_info->author->data;
1156 return PMINFO_R_ERROR;
1157 if (author->href == NULL)
1158 author->href = strdup("");
1160 *author_href = (char *)author->href;
1165 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1167 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1169 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1170 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1172 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1173 return PMINFO_R_ERROR;
1175 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1176 *storage = PMINFO_INTERNAL_STORAGE;
1177 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1178 *storage = PMINFO_EXTERNAL_STORAGE;
1180 return PMINFO_R_ERROR;
1185 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1187 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1189 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1190 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1192 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1193 return PMINFO_R_ERROR;
1195 *installed_time = atoi(info->pkg_info->installed_time);
1200 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1202 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1205 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1207 if (info->pkg_info == NULL)
1208 return PMINFO_R_ERROR;
1209 if (info->pkg_info->storeclient_id == NULL)
1210 info->pkg_info->storeclient_id = strdup("");
1212 *storeclientid = (char *)info->pkg_info->storeclient_id;
1217 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1219 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1222 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1224 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1225 return PMINFO_R_ERROR;
1227 *mainappid = (char *)info->pkg_info->mainapp_id;
1232 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1234 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1237 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 if (info->pkg_info == NULL)
1240 return PMINFO_R_ERROR;
1241 if (info->pkg_info->package_url == NULL)
1242 info->pkg_info->package_url = strdup("");
1244 *url = (char *)info->pkg_info->package_url;
1249 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1251 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1253 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1254 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1256 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1257 return PMINFO_R_ERROR;
1259 *path = (char *)info->pkg_info->root_path;
1264 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1266 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1268 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1269 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1271 if (info->pkg_info == NULL)
1272 return PMINFO_R_ERROR;
1273 if (info->pkg_info->csc_path == NULL)
1274 info->pkg_info->csc_path = strdup("");
1276 *path = (char *)info->pkg_info->csc_path;
1282 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1284 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1285 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1287 #if 0 //smack issue occured, check later
1289 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1291 _LOGD("invalid func parameters\n");
1292 return PMINFO_R_ERROR;
1294 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1297 char app_mmc_path[FILENAME_MAX] = { 0, };
1298 char app_dir_path[FILENAME_MAX] = { 0, };
1299 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1300 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1301 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1302 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1304 /*check whether application is in external memory or not */
1305 fp = fopen(app_mmc_path, "r");
1307 _LOGD(" app path in external memory not accesible\n");
1312 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1316 /*check whether application is in internal or not */
1318 _LOGD(" app path in internal memory not accesible\n");
1320 return PMINFO_R_ERROR;
1323 /*check whether the application is installed in SD card
1324 but SD card is not present*/
1325 fp = fopen(app_mmc_internal_path, "r");
1328 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1333 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1338 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1345 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1347 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1350 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1352 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1353 return PMINFO_R_ERROR;
1355 *removable = _get_bool_value(info->pkg_info->removable);
1360 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1363 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1366 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1368 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1369 return PMINFO_R_ERROR;
1371 val = (char *)info->pkg_info->installlocation;
1372 if (strcmp(val, "internal-only") == 0)
1374 else if (strcmp(val, "prefer-external") == 0)
1382 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1384 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1386 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1387 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1389 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1390 return PMINFO_R_ERROR;
1392 *preload = _get_bool_value(info->pkg_info->preload);
1397 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1399 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1401 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1402 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1404 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1405 return PMINFO_R_ERROR;
1407 *system = _get_bool_value(info->pkg_info->system);
1412 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1414 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1417 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1419 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1420 return PMINFO_R_ERROR;
1422 *readonly = _get_bool_value(info->pkg_info->readonly);
1427 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1429 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1431 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1432 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1434 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1435 return PMINFO_R_ERROR;
1437 *update = _get_bool_value(info->pkg_info->update);
1442 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1444 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1446 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1447 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1449 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1450 return PMINFO_R_ERROR;
1452 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1457 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1459 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1461 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1462 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1464 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1465 return PMINFO_R_ERROR;
1467 *global = _get_bool_value(info->pkg_info->for_all_users);
1472 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1474 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1477 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1479 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1481 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1483 __cleanup_pkginfo(info);
1488 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1490 pkgmgrinfo_filter_x *filter;
1492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1494 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1495 if (filter == NULL) {
1496 _LOGE("Out of Memory!!!");
1497 return PMINFO_R_ERROR;
1505 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1507 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1512 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1513 g_slist_free(filter->list);
1521 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1522 const char *property, const int value)
1524 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1528 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1529 pkgmgrinfo_node_x *node;
1531 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1532 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1534 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1535 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1536 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1537 _LOGE("Invalid Integer Property\n");
1538 return PMINFO_R_EINVAL;
1540 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1542 _LOGE("Out of Memory!!!\n");
1543 return PMINFO_R_ERROR;
1545 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1546 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1548 _LOGE("Out of Memory\n");
1550 return PMINFO_R_ERROR;
1554 /*If API is called multiple times for same property, we should override the previous values.
1555 Last value set will be used for filtering.*/
1556 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1558 filter->list = g_slist_delete_link(filter->list, link);
1559 filter->list = g_slist_append(filter->list, (gpointer)node);
1564 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1565 const char *property, const bool value)
1570 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1571 pkgmgrinfo_node_x *node;
1573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1574 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1576 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1577 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1578 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1579 _LOGE("Invalid Boolean Property\n");
1580 return PMINFO_R_EINVAL;
1582 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1584 _LOGE("Out of Memory!!!\n");
1585 return PMINFO_R_ERROR;
1588 val = strndup("true", 4);
1590 val = strndup("false", 5);
1592 _LOGE("Out of Memory\n");
1594 return PMINFO_R_ERROR;
1598 /*If API is called multiple times for same property, we should override the previous values.
1599 Last value set will be used for filtering.*/
1600 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1602 filter->list = g_slist_delete_link(filter->list, link);
1603 filter->list = g_slist_append(filter->list, (gpointer)node);
1608 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1609 const char *property, const char *value)
1614 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1615 pkgmgrinfo_node_x *node;
1617 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1618 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1619 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1621 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1622 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1623 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1624 _LOGE("Invalid String Property\n");
1625 return PMINFO_R_EINVAL;
1627 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1629 _LOGE("Out of Memory!!!\n");
1630 return PMINFO_R_ERROR;
1632 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1633 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1634 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1635 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1636 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1637 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1638 else if (strcmp(value, "installed_internal") == 0)
1639 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1640 else if (strcmp(value, "installed_external") == 0)
1641 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1643 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1645 _LOGE("Out of Memory\n");
1647 return PMINFO_R_ERROR;
1651 /*If API is called multiple times for same property, we should override the previous values.
1652 Last value set will be used for filtering.*/
1653 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1655 filter->list = g_slist_delete_link(filter->list, link);
1656 filter->list = g_slist_append(filter->list, (gpointer)node);
1661 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1665 GHashTable *list = NULL;
1667 if (handle == NULL || count == NULL) {
1668 _LOGE("invalid parameter");
1669 return PMINFO_R_EINVAL;
1672 locale = _get_system_locale();
1674 return PMINFO_R_ERROR;
1676 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1680 return PMINFO_R_ERROR;
1683 ret = _pkginfo_get_packages(uid, locale,
1684 (pkgmgrinfo_filter_x *)handle, 0, list);
1685 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1686 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1689 if (ret != PMINFO_R_OK) {
1690 g_hash_table_destroy(list);
1692 return PMINFO_R_ERROR;
1695 *count = g_hash_table_size(list);
1697 g_hash_table_destroy(list);
1703 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1705 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1708 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1709 pkgmgrinfo_pkginfo_filter_h handle,
1710 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1712 if (handle == NULL || pkg_cb == NULL) {
1713 LOGE("invalid parameter");
1714 return PMINFO_R_EINVAL;
1717 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1718 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1721 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1722 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1724 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1727 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1728 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1730 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1731 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1733 const char *privilege;
1735 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1737 if (info->pkg_info == NULL)
1738 return PMINFO_R_ERROR;
1740 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1741 privilege = (const char *)tmp->data;
1742 if (privilege == NULL)
1744 ret = privilege_func(privilege, user_data);