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_get_author(sqlite3 *db, const char *pkgid,
155 static const char query_raw[] =
156 "SELECT author_name, author_email, author_href "
157 "FROM package_info WHERE package=%Q";
164 query = sqlite3_mprintf(query_raw, pkgid);
166 LOGE("out of memory");
167 return PMINFO_R_ERROR;
170 ret = sqlite3_prepare_v2(db, query, strlen(query),
173 if (ret != SQLITE_OK) {
174 LOGE("prepare failed: %s", sqlite3_errmsg(db));
175 return PMINFO_R_ERROR;
178 if (sqlite3_step(stmt) == SQLITE_ERROR) {
179 LOGE("step error: %s", sqlite3_errmsg(db));
180 sqlite3_finalize(stmt);
181 return PMINFO_R_ERROR;
184 /* one author per one package */
185 info = calloc(1, sizeof(author_x));
187 LOGE("out of memory");
188 sqlite3_finalize(stmt);
189 return PMINFO_R_ERROR;
192 _save_column_str(stmt, idx++, &info->text);
193 _save_column_str(stmt, idx++, &info->email);
194 _save_column_str(stmt, idx++, &info->href);
197 *author = g_list_append(*author, info);
199 sqlite3_finalize(stmt);
204 static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
205 const char *locale, GList **label)
207 static const char query_raw[] =
208 "SELECT package_label, package_locale "
209 "FROM package_localized_info "
210 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
217 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
219 LOGE("out of memory");
220 return PMINFO_R_ERROR;
223 ret = sqlite3_prepare_v2(db, query, strlen(query),
226 if (ret != SQLITE_OK) {
227 LOGE("prepare failed: %s", sqlite3_errmsg(db));
228 return PMINFO_R_ERROR;
231 while (sqlite3_step(stmt) == SQLITE_ROW) {
232 info = calloc(1, sizeof(label_x));
234 LOGE("out of memory");
235 sqlite3_finalize(stmt);
236 return PMINFO_R_ERROR;
239 _save_column_str(stmt, idx++, &info->text);
240 _save_column_str(stmt, idx++, &info->lang);
241 *label = g_list_append(*label, info);
244 sqlite3_finalize(stmt);
249 static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
252 static const char query_raw[] =
253 "SELECT package_icon, package_locale "
254 "FROM package_localized_info "
255 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
262 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
264 LOGE("out of memory");
265 return PMINFO_R_ERROR;
268 ret = sqlite3_prepare_v2(db, query, strlen(query),
271 if (ret != SQLITE_OK) {
272 LOGE("prepare failed: %s", sqlite3_errmsg(db));
273 return PMINFO_R_ERROR;
276 while (sqlite3_step(stmt) == SQLITE_ROW) {
277 info = calloc(1, sizeof(icon_x));
279 LOGE("out of memory");
280 sqlite3_finalize(stmt);
281 return PMINFO_R_ERROR;
284 _save_column_str(stmt, idx++, &info->text);
285 _save_column_str(stmt, idx++, &info->lang);
286 *icon = g_list_append(*icon, info);
289 sqlite3_finalize(stmt);
294 static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
295 const char *locale, GList **description)
297 static const char query_raw[] =
298 "SELECT package_description, package_locale "
299 "FROM package_localized_info "
300 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
307 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
309 LOGE("out of memory");
310 return PMINFO_R_ERROR;
313 ret = sqlite3_prepare_v2(db, query, strlen(query),
316 if (ret != SQLITE_OK) {
317 LOGE("prepare failed: %s", sqlite3_errmsg(db));
318 return PMINFO_R_ERROR;
321 while (sqlite3_step(stmt) == SQLITE_ROW) {
322 info = calloc(1, sizeof(description_x));
324 LOGE("out of memory");
325 sqlite3_finalize(stmt);
326 return PMINFO_R_ERROR;
329 _save_column_str(stmt, idx++, &info->text);
330 _save_column_str(stmt, idx++, &info->lang);
331 *description = g_list_append(*description, info);
334 sqlite3_finalize(stmt);
339 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
342 static const char query_raw[] =
343 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
349 query = sqlite3_mprintf(query_raw, pkgid);
351 LOGE("out of memory");
352 return PMINFO_R_ERROR;
355 ret = sqlite3_prepare_v2(db, query, strlen(query),
358 if (ret != SQLITE_OK) {
359 LOGE("prepare failed: %s", sqlite3_errmsg(db));
360 return PMINFO_R_ERROR;
363 while (sqlite3_step(stmt) == SQLITE_ROW) {
365 _save_column_str(stmt, 0, &privilege);
367 *privileges = g_list_append(*privileges,
368 (gpointer)privilege);
371 sqlite3_finalize(stmt);
376 static const char join_localized_info[] =
377 " LEFT OUTER JOIN package_localized_info"
378 " ON pi.package=package_localized_info.package"
379 " AND package_localized_info.package_locale=?";
380 static const char join_privilege_info[] =
381 " LEFT OUTER JOIN package_privilege_info"
382 " ON pi.package=package_privilege_info.package";
384 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
385 const char *locale, char **query, GList **bind_params)
388 char buf[MAX_QUERY_LEN] = { '\0' };
389 char buf2[MAX_QUERY_LEN] = { '\0' };
390 char *condition = NULL;
397 len += strlen(" WHERE 1=1 ");
398 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
399 for (list = filter->list; list; list = list->next) {
400 joined |= __get_filter_condition(list->data, &condition,
402 if (condition == NULL)
405 len += strlen(" AND ");
406 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
408 len += strlen(condition);
409 strncat(buf, condition, sizeof(buf) - len - 1);
414 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
415 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
416 len += strlen(join_localized_info);
417 *bind_params = g_list_append(*bind_params, strdup(locale));
419 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
420 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
421 len += strlen(join_privilege_info);
423 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
425 *query = strdup(buf2);
427 return PMINFO_R_ERROR;
432 static void __free_packages(gpointer data)
434 pkgmgrinfo_basic_free_package((package_x *)data);
437 static int __bind_params(sqlite3_stmt *stmt, GList *params)
439 GList *tmp_list = NULL;
443 if (stmt == NULL || params == NULL)
444 return PMINFO_R_EINVAL;
448 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
449 if (ret != SQLITE_OK)
450 return PMINFO_R_ERROR;
451 tmp_list = tmp_list->next;
457 static int _pkginfo_get_packages(uid_t uid, const char *locale,
458 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
460 static const char query_raw[] =
461 "SELECT DISTINCT pi.package, pi.package_version, "
462 "pi.install_location, pi.package_removable, "
463 "pi.package_preload, pi.package_readonly, pi.package_update, "
464 "pi.package_appsetting, pi.package_system, pi.package_type, "
465 "pi.package_size, pi.installed_time, pi.installed_storage, "
466 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
467 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
468 "pi.package_api_version, pi.package_support_disable, "
469 "pi.package_tep_name, pi.package_zip_mount_file "
470 "FROM package_info as pi ";
471 int ret = PMINFO_R_ERROR;
474 char *constraints = NULL;
475 char query[MAX_QUERY_LEN] = { '\0' };
476 package_x *info = NULL;
477 GList *bind_params = NULL;
480 pkgmgrinfo_filter_x *tmp_filter = NULL;
482 dbpath = getUserPkgParserDBPathUID(uid);
484 return PMINFO_R_ERROR;
486 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
487 if (ret != SQLITE_OK) {
488 _LOGD("failed to open db: %d", ret);
489 return PMINFO_R_ERROR;
492 if (filter != NULL) {
495 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
496 if (ret != PMINFO_R_OK) {
497 _LOGE("Failed to create filter");
498 return PMINFO_R_ERROR;
502 /* add package_disable='false' clause by default */
503 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
505 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
506 if (ret != PMINFO_R_OK) {
507 LOGE("Failed to get WHERE clause");
512 snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraints);
514 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
516 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
517 if (ret != SQLITE_OK) {
518 LOGE("prepare failed: %s", sqlite3_errmsg(db));
519 ret = PMINFO_R_ERROR;
523 ret = __bind_params(stmt, bind_params);
524 if (ret != SQLITE_OK) {
525 LOGE("Failed to bind parameters");
529 while (sqlite3_step(stmt) == SQLITE_ROW) {
530 info = calloc(1, sizeof(package_x));
532 LOGE("out of memory");
533 sqlite3_finalize(stmt);
534 sqlite3_close_v2(db);
535 return PMINFO_R_ERROR;
538 _save_column_str(stmt, idx++, &info->package);
539 if (g_hash_table_contains(packages,
540 (gconstpointer)info->package)) {
545 _save_column_str(stmt, idx++, &info->version);
546 _save_column_str(stmt, idx++, &info->installlocation);
547 _save_column_str(stmt, idx++, &info->removable);
548 _save_column_str(stmt, idx++, &info->preload);
549 _save_column_str(stmt, idx++, &info->readonly);
550 _save_column_str(stmt, idx++, &info->update);
551 _save_column_str(stmt, idx++, &info->appsetting);
552 _save_column_str(stmt, idx++, &info->system);
553 _save_column_str(stmt, idx++, &info->type);
554 _save_column_str(stmt, idx++, &info->package_size);
555 _save_column_str(stmt, idx++, &info->installed_time);
556 _save_column_str(stmt, idx++, &info->installed_storage);
557 _save_column_str(stmt, idx++, &info->storeclient_id);
558 _save_column_str(stmt, idx++, &info->mainapp_id);
559 _save_column_str(stmt, idx++, &info->package_url);
560 _save_column_str(stmt, idx++, &info->root_path);
561 _save_column_str(stmt, idx++, &info->csc_path);
562 _save_column_str(stmt, idx++, &info->nodisplay_setting);
563 _save_column_str(stmt, idx++, &info->api_version);
564 _save_column_str(stmt, idx++, &info->support_disable);
565 _save_column_str(stmt, idx++, &info->tep_name);
566 _save_column_str(stmt, idx++, &info->zip_mount_file);
567 info->for_all_users =
568 strdup((uid != GLOBAL_USER) ? "false" : "true");
570 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
571 if (_pkginfo_get_author(db, info->package,
573 pkgmgrinfo_basic_free_package(info);
574 sqlite3_finalize(stmt);
575 sqlite3_close_v2(db);
576 return PMINFO_R_ERROR;
580 if (flag & PMINFO_PKGINFO_GET_LABEL) {
581 if (_pkginfo_get_label(db, info->package, locale,
583 pkgmgrinfo_basic_free_package(info);
584 sqlite3_finalize(stmt);
585 sqlite3_close_v2(db);
586 return PMINFO_R_ERROR;
590 if (flag & PMINFO_PKGINFO_GET_ICON) {
591 if (_pkginfo_get_icon(db, info->package, locale,
593 pkgmgrinfo_basic_free_package(info);
594 sqlite3_finalize(stmt);
595 sqlite3_close_v2(db);
596 return PMINFO_R_ERROR;
600 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
601 if (_pkginfo_get_description(db, info->package, locale,
602 &info->description)) {
603 pkgmgrinfo_basic_free_package(info);
604 sqlite3_finalize(stmt);
605 sqlite3_close_v2(db);
606 return PMINFO_R_ERROR;
610 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
611 if (_pkginfo_get_privilege(db, info->package,
612 &info->privileges)) {
613 pkgmgrinfo_basic_free_package(info);
614 sqlite3_finalize(stmt);
615 sqlite3_close_v2(db);
616 return PMINFO_R_ERROR;
620 g_hash_table_insert(packages, (gpointer)info->package,
630 if (ret != PMINFO_R_OK && info != NULL)
631 pkgmgrinfo_basic_free_package(info);
634 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
636 g_list_free_full(bind_params, free);
637 sqlite3_close_v2(db);
638 sqlite3_finalize(stmt);
643 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
644 pkgmgrinfo_filter_x *filter, int flag,
645 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
650 pkgmgr_pkginfo_x info;
655 locale = _get_system_locale();
657 return PMINFO_R_ERROR;
659 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
663 return PMINFO_R_ERROR;
666 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
667 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
668 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
671 if (ret != PMINFO_R_OK) {
672 g_hash_table_destroy(list);
674 return PMINFO_R_ERROR;
677 g_hash_table_iter_init(&iter, list);
678 while (g_hash_table_iter_next(&iter, NULL, &value)) {
679 pkg = (package_x *)value;
682 info.locale = locale;
683 if (pkg_list_cb(&info, user_data) < 0)
687 g_hash_table_destroy(list);
693 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
694 pkgmgrinfo_pkginfo_h *handle)
699 pkgmgrinfo_pkginfo_filter_h filter;
700 pkgmgr_pkginfo_x *info;
702 if (pkgid == NULL || handle == NULL) {
703 LOGE("invalid parameter");
704 return PMINFO_R_EINVAL;
707 locale = _get_system_locale();
709 return PMINFO_R_ERROR;
711 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
712 if (ret != PMINFO_R_OK) {
717 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
718 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
719 if (ret != PMINFO_R_OK) {
720 pkgmgrinfo_pkginfo_filter_destroy(filter);
722 return PMINFO_R_ERROR;
725 list = g_hash_table_new(g_str_hash, g_str_equal);
727 pkgmgrinfo_pkginfo_filter_destroy(filter);
729 return PMINFO_R_ERROR;
732 ret = _pkginfo_get_packages(uid, locale, filter,
733 PMINFO_PKGINFO_GET_ALL, list);
734 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
735 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
736 PMINFO_PKGINFO_GET_ALL, list);
738 pkgmgrinfo_pkginfo_filter_destroy(filter);
739 if (ret != PMINFO_R_OK) {
740 g_hash_table_destroy(list);
745 if (!g_hash_table_size(list)) {
746 _LOGI("pkginfo for [%s] is not existed for user [%d]",
748 g_hash_table_destroy(list);
750 return PMINFO_R_ENOENT;
753 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
755 _LOGE("out of memory");
756 g_hash_table_destroy(list);
758 return PMINFO_R_ERROR;
762 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
763 info->locale = locale;
765 /* just free list only */
766 g_hash_table_destroy(list);
773 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
774 pkgmgrinfo_pkginfo_h *handle)
776 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
779 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
780 int flag, void *user_data, uid_t uid)
782 if (pkg_list_cb == NULL) {
783 LOGE("invalid parameter");
784 return PMINFO_R_EINVAL;
787 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
788 pkg_list_cb, user_data);
791 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
792 int flag, void *user_data)
794 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
795 user_data, _getuid());
798 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
799 void *user_data, uid_t uid)
801 if (pkg_list_cb == NULL) {
802 LOGE("invalid parameter");
803 return PMINFO_R_EINVAL;
806 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
807 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
810 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
813 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
817 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
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(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
824 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
825 return PMINFO_R_ERROR;
827 *pkg_name = (char *)info->pkg_info->package;
832 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
834 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
836 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
837 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
839 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
840 return PMINFO_R_ERROR;
842 *pkgid = (char *)info->pkg_info->package;
847 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
849 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
852 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
854 if (info->pkg_info == NULL)
855 return PMINFO_R_ERROR;
856 if (info->pkg_info->type == NULL)
857 info->pkg_info->type = strdup("");
859 *type = (char *)info->pkg_info->type;
864 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
866 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
869 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
871 if (info->pkg_info == NULL)
872 return PMINFO_R_ERROR;
873 if (info->pkg_info->version == NULL)
874 info->pkg_info->version = strdup("");
876 *version = (char *)info->pkg_info->version;
881 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
883 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
885 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
886 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
888 if (info->pkg_info == NULL)
889 return PMINFO_R_ERROR;
890 if (info->pkg_info->api_version == NULL)
891 info->pkg_info->api_version = strdup("");
893 *api_version = (char *)info->pkg_info->api_version;
898 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
900 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
902 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
903 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
905 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
906 return PMINFO_R_ERROR;
908 *tep_name = (char *)info->pkg_info->tep_name;
913 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
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(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
920 if (info->pkg_info == NULL)
921 return PMINFO_R_ERROR;
922 if (info->pkg_info->zip_mount_file == NULL)
923 info->pkg_info->zip_mount_file = strdup("");
925 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
930 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
933 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
935 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
936 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
938 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
939 return PMINFO_R_ERROR;
941 val = (char *)info->pkg_info->installlocation;
942 if (strcmp(val, "internal-only") == 0)
943 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
944 else if (strcmp(val, "prefer-external") == 0)
945 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
947 *location = PMINFO_INSTALL_LOCATION_AUTO;
952 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
954 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
957 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
958 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
960 if (info->pkg_info == NULL)
961 return PMINFO_R_ERROR;
963 if (info->pkg_info->package_size == NULL) {
966 _LOGE("out of memory");
967 return PMINFO_R_ERROR;
969 info->pkg_info->package_size = temp;
973 *size = atoi((char *)info->pkg_info->package_size);
978 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
983 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
986 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
988 locale = info->locale;
989 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
991 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
992 return PMINFO_R_ERROR;
994 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
995 ptr = (icon_x *)tmp->data;
996 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
997 strcmp(ptr->lang, locale))
999 *icon = (char *)ptr->text;
1003 locale = DEFAULT_LOCALE;
1004 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1005 ptr = (icon_x *)tmp->data;
1006 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1007 strcmp(ptr->lang, locale))
1009 *icon = (char *)ptr->text;
1018 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1023 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1025 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1026 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1028 locale = info->locale;
1029 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1031 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1032 return PMINFO_R_ERROR;
1034 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1035 ptr = (label_x *)tmp->data;
1036 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1037 strcmp(ptr->lang, locale))
1039 *label = (char *)ptr->text;
1043 locale = DEFAULT_LOCALE;
1044 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1045 ptr = (label_x *)tmp->data;
1046 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1047 strcmp(ptr->lang, locale))
1049 *label = (char *)ptr->text;
1058 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1063 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1066 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1068 locale = info->locale;
1069 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1071 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1072 return PMINFO_R_ERROR;
1074 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1075 ptr = (description_x *)tmp->data;
1076 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1077 strcmp(ptr->lang, locale))
1079 *description = (char *)ptr->text;
1083 locale = DEFAULT_LOCALE;
1084 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1085 ptr = (description_x *)tmp->data;
1086 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1087 strcmp(ptr->lang, locale))
1089 *description = (char *)ptr->text;
1098 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1100 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1104 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1106 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1107 return PMINFO_R_ERROR;
1109 author = (author_x *)info->pkg_info->author->data;
1111 return PMINFO_R_ERROR;
1112 if (author->text == NULL)
1113 author->text = strdup("");
1115 *author_name = (char *)author->text;
1120 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1122 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1126 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1128 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1129 return PMINFO_R_ERROR;
1131 author = (author_x *)info->pkg_info->author->data;
1133 return PMINFO_R_ERROR;
1134 if (author->email == NULL)
1135 author->email = strdup("");
1137 *author_email = (char *)author->email;
1142 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1144 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1148 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1150 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1151 return PMINFO_R_ERROR;
1153 author = (author_x *)info->pkg_info->author->data;
1155 return PMINFO_R_ERROR;
1156 if (author->href == NULL)
1157 author->href = strdup("");
1159 *author_href = (char *)author->href;
1164 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1166 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1169 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1171 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1172 return PMINFO_R_ERROR;
1174 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1175 *storage = PMINFO_INTERNAL_STORAGE;
1176 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1177 *storage = PMINFO_EXTERNAL_STORAGE;
1179 return PMINFO_R_ERROR;
1184 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1186 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1188 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1189 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1191 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1192 return PMINFO_R_ERROR;
1194 *installed_time = atoi(info->pkg_info->installed_time);
1199 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1201 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1204 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1206 if (info->pkg_info == NULL)
1207 return PMINFO_R_ERROR;
1208 if (info->pkg_info->storeclient_id == NULL)
1209 info->pkg_info->storeclient_id = strdup("");
1211 *storeclientid = (char *)info->pkg_info->storeclient_id;
1216 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1218 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1221 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1223 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1224 return PMINFO_R_ERROR;
1226 *mainappid = (char *)info->pkg_info->mainapp_id;
1231 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1233 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1235 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1236 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1238 if (info->pkg_info == NULL)
1239 return PMINFO_R_ERROR;
1240 if (info->pkg_info->package_url == NULL)
1241 info->pkg_info->package_url = strdup("");
1243 *url = (char *)info->pkg_info->package_url;
1248 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1250 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1252 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1253 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1255 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1256 return PMINFO_R_ERROR;
1258 *path = (char *)info->pkg_info->root_path;
1263 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1265 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1267 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1268 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1270 if (info->pkg_info == NULL)
1271 return PMINFO_R_ERROR;
1272 if (info->pkg_info->csc_path == NULL)
1273 info->pkg_info->csc_path = strdup("");
1275 *path = (char *)info->pkg_info->csc_path;
1281 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1283 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1284 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1286 #if 0 /* smack issue occured, check later */
1288 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1289 if (pkgid == NULL) {
1290 _LOGD("invalid func parameters\n");
1291 return PMINFO_R_ERROR;
1293 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1296 char app_mmc_path[FILENAME_MAX] = { 0, };
1297 char app_dir_path[FILENAME_MAX] = { 0, };
1298 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1299 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1300 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1301 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1303 /*check whether application is in external memory or not */
1304 fp = fopen(app_mmc_path, "r");
1306 _LOGD(" app path in external memory not accesible\n");
1311 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1315 /*check whether application is in internal or not */
1317 _LOGD(" app path in internal memory not accesible\n");
1319 return PMINFO_R_ERROR;
1322 /*check whether the application is installed in SD card
1323 but SD card is not present*/
1324 fp = fopen(app_mmc_internal_path, "r");
1327 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1331 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1336 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1343 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1345 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1348 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1350 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1351 return PMINFO_R_ERROR;
1353 *removable = _get_bool_value(info->pkg_info->removable);
1358 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1361 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1364 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1366 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1367 return PMINFO_R_ERROR;
1369 val = (char *)info->pkg_info->installlocation;
1370 if (strcmp(val, "internal-only") == 0)
1372 else if (strcmp(val, "prefer-external") == 0)
1380 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1384 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1385 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1387 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1388 return PMINFO_R_ERROR;
1390 *preload = _get_bool_value(info->pkg_info->preload);
1395 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1397 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1399 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1400 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1402 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1403 return PMINFO_R_ERROR;
1405 *system = _get_bool_value(info->pkg_info->system);
1410 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1412 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1415 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1417 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1418 return PMINFO_R_ERROR;
1420 *readonly = _get_bool_value(info->pkg_info->readonly);
1425 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1427 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1429 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1430 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1432 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1433 return PMINFO_R_ERROR;
1435 *update = _get_bool_value(info->pkg_info->update);
1440 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1442 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1445 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1447 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1448 return PMINFO_R_ERROR;
1450 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1455 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1457 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1460 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1462 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1463 return PMINFO_R_ERROR;
1465 *global = _get_bool_value(info->pkg_info->for_all_users);
1470 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1472 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1475 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1477 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1479 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1481 __cleanup_pkginfo(info);
1486 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1488 pkgmgrinfo_filter_x *filter;
1490 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1492 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1493 if (filter == NULL) {
1494 _LOGE("Out of Memory!!!");
1495 return PMINFO_R_ERROR;
1503 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1505 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1507 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1510 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1511 g_slist_free(filter->list);
1519 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1520 const char *property, const int value)
1522 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1526 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1527 pkgmgrinfo_node_x *node;
1529 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1530 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1532 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1533 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1534 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1535 _LOGE("Invalid Integer Property\n");
1536 return PMINFO_R_EINVAL;
1538 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1540 _LOGE("Out of Memory!!!\n");
1541 return PMINFO_R_ERROR;
1543 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1544 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1546 _LOGE("Out of Memory\n");
1548 return PMINFO_R_ERROR;
1552 /*If API is called multiple times for same property, we should override the previous values.
1553 Last value set will be used for filtering.*/
1554 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1556 filter->list = g_slist_delete_link(filter->list, link);
1557 filter->list = g_slist_append(filter->list, (gpointer)node);
1562 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1563 const char *property, const bool value)
1568 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1569 pkgmgrinfo_node_x *node;
1571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1572 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1574 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1575 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1576 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1577 _LOGE("Invalid Boolean Property\n");
1578 return PMINFO_R_EINVAL;
1580 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1582 _LOGE("Out of Memory!!!\n");
1583 return PMINFO_R_ERROR;
1586 val = strndup("true", 4);
1588 val = strndup("false", 5);
1590 _LOGE("Out of Memory\n");
1592 return PMINFO_R_ERROR;
1596 /*If API is called multiple times for same property, we should override the previous values.
1597 Last value set will be used for filtering.*/
1598 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1600 filter->list = g_slist_delete_link(filter->list, link);
1601 filter->list = g_slist_append(filter->list, (gpointer)node);
1606 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1607 const char *property, const char *value)
1612 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1613 pkgmgrinfo_node_x *node;
1615 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1616 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1617 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1619 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1620 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1621 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1622 _LOGE("Invalid String Property\n");
1623 return PMINFO_R_EINVAL;
1625 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1627 _LOGE("Out of Memory!!!\n");
1628 return PMINFO_R_ERROR;
1630 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1631 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1632 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1633 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1634 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1635 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1636 else if (strcmp(value, "installed_internal") == 0)
1637 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1638 else if (strcmp(value, "installed_external") == 0)
1639 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1641 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1643 _LOGE("Out of Memory\n");
1645 return PMINFO_R_ERROR;
1649 /*If API is called multiple times for same property, we should override the previous values.
1650 Last value set will be used for filtering.*/
1651 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1653 filter->list = g_slist_delete_link(filter->list, link);
1654 filter->list = g_slist_append(filter->list, (gpointer)node);
1659 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1663 GHashTable *list = NULL;
1665 if (handle == NULL || count == NULL) {
1666 _LOGE("invalid parameter");
1667 return PMINFO_R_EINVAL;
1670 locale = _get_system_locale();
1672 return PMINFO_R_ERROR;
1674 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1678 return PMINFO_R_ERROR;
1681 ret = _pkginfo_get_packages(uid, locale,
1682 (pkgmgrinfo_filter_x *)handle, 0, list);
1683 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1684 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1687 if (ret != PMINFO_R_OK) {
1688 g_hash_table_destroy(list);
1690 return PMINFO_R_ERROR;
1693 *count = g_hash_table_size(list);
1695 g_hash_table_destroy(list);
1701 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1703 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1706 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1707 pkgmgrinfo_pkginfo_filter_h handle,
1708 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1710 if (handle == NULL || pkg_cb == NULL) {
1711 LOGE("invalid parameter");
1712 return PMINFO_R_EINVAL;
1715 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1716 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1719 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1720 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1722 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1725 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1726 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1728 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1729 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1731 const char *privilege;
1733 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1735 if (info->pkg_info == NULL)
1736 return PMINFO_R_ERROR;
1738 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1739 privilege = (const char *)tmp->data;
1740 if (privilege == NULL)
1742 ret = privilege_func(privilege, user_data);