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>
35 #include <libxml/parser.h>
36 #include <libxml/xmlreader.h>
37 #include <libxml/xmlschemas.h>
41 #include "pkgmgr_parser.h"
42 #include "pkgmgrinfo_basic.h"
43 #include "pkgmgrinfo_private.h"
44 #include "pkgmgrinfo_debug.h"
45 #include "pkgmgr-info.h"
46 #include "pkgmgr_parser_db.h"
47 #include "pkgmgr_parser_internal.h"
49 static bool _get_bool_value(const char *str)
51 if (str && !strcmp(str, "true"))
57 static gint __compare_func(gconstpointer data1, gconstpointer data2)
59 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
60 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
61 if (node1->prop == node2->prop)
63 else if (node1->prop > node2->prop)
69 static void __destroy_each_node(gpointer data, gpointer user_data)
72 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
85 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
89 free((void *)data->locale);
93 pkgmgrinfo_basic_free_package(data->pkg_info);
99 static int __child_element(xmlTextReaderPtr reader, int depth)
101 int ret = xmlTextReaderRead(reader);
102 int cur = xmlTextReaderDepth(reader);
105 switch (xmlTextReaderNodeType(reader)) {
106 case XML_READER_TYPE_ELEMENT:
107 if (cur == depth + 1)
110 case XML_READER_TYPE_TEXT:
111 /*text is handled by each function separately*/
112 if (cur == depth + 1)
115 case XML_READER_TYPE_END_ELEMENT:
124 ret = xmlTextReaderRead(reader);
125 cur = xmlTextReaderDepth(reader);
130 long long _pkgmgr_calculate_dir_size(char *dirname)
134 int q = 0; /*quotient*/
135 int r = 0; /*remainder*/
137 struct dirent ep, *result;
138 struct stat fileinfo;
139 char abs_filename[FILENAME_MAX] = { 0, };
140 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
142 dp = opendir(dirname);
144 _LOGE("Couldn't open the directory\n");
148 for (ret = readdir_r(dp, &ep, &result);
149 ret == 0 && result != NULL;
150 ret = readdir_r(dp, &ep, &result)) {
151 if (!strcmp(ep.d_name, ".") ||
152 !strcmp(ep.d_name, "..")) {
155 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
157 if (lstat(abs_filename, &fileinfo) < 0)
158 perror(abs_filename);
160 if (S_ISDIR(fileinfo.st_mode)) {
161 total += fileinfo.st_size;
162 if (strcmp(ep.d_name, ".")
163 && strcmp(ep.d_name, "..")) {
164 ret = _pkgmgr_calculate_dir_size
168 } else if (S_ISLNK(fileinfo.st_mode)) {
171 /*It is a file. Calculate the actual
172 size occupied (in terms of 4096 blocks)*/
173 q = (fileinfo.st_size / BLOCK_SIZE);
174 r = (fileinfo.st_size % BLOCK_SIZE);
178 total += q * BLOCK_SIZE;
187 static int _pkginfo_get_author(sqlite3 *db, const char *pkgid,
190 static const char query_raw[] =
191 "SELECT author_name, author_email, author_href "
192 "FROM package_info WHERE package=%Q";
199 query = sqlite3_mprintf(query_raw, pkgid);
201 LOGE("out of memory");
202 return PMINFO_R_ERROR;
205 ret = sqlite3_prepare_v2(db, query, strlen(query),
208 if (ret != SQLITE_OK) {
209 LOGE("prepare failed: %s", sqlite3_errmsg(db));
210 return PMINFO_R_ERROR;
213 if (sqlite3_step(stmt) == SQLITE_ERROR) {
214 LOGE("step error: %s", sqlite3_errmsg(db));
215 sqlite3_finalize(stmt);
216 return PMINFO_R_ERROR;
219 /* one author per one package */
220 info = calloc(1, sizeof(author_x));
222 LOGE("out of memory");
223 sqlite3_finalize(stmt);
224 return PMINFO_R_ERROR;
227 _save_column_str(stmt, idx++, &info->text);
228 _save_column_str(stmt, idx++, &info->email);
229 _save_column_str(stmt, idx++, &info->href);
232 *author = g_list_append(*author, info);
234 sqlite3_finalize(stmt);
239 static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
240 const char *locale, GList **label)
242 static const char query_raw[] =
243 "SELECT package_label, package_locale "
244 "FROM package_localized_info "
245 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
252 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
254 LOGE("out of memory");
255 return PMINFO_R_ERROR;
258 ret = sqlite3_prepare_v2(db, query, strlen(query),
261 if (ret != SQLITE_OK) {
262 LOGE("prepare failed: %s", sqlite3_errmsg(db));
263 return PMINFO_R_ERROR;
266 while (sqlite3_step(stmt) == SQLITE_ROW) {
267 info = calloc(1, sizeof(label_x));
269 LOGE("out of memory");
270 sqlite3_finalize(stmt);
271 return PMINFO_R_ERROR;
274 _save_column_str(stmt, idx++, &info->text);
275 _save_column_str(stmt, idx++, &info->lang);
276 *label = g_list_append(*label, info);
279 sqlite3_finalize(stmt);
284 static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
287 static const char query_raw[] =
288 "SELECT package_icon, package_locale "
289 "FROM package_localized_info "
290 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
297 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
299 LOGE("out of memory");
300 return PMINFO_R_ERROR;
303 ret = sqlite3_prepare_v2(db, query, strlen(query),
306 if (ret != SQLITE_OK) {
307 LOGE("prepare failed: %s", sqlite3_errmsg(db));
308 return PMINFO_R_ERROR;
311 while (sqlite3_step(stmt) == SQLITE_ROW) {
312 info = calloc(1, sizeof(icon_x));
314 LOGE("out of memory");
315 sqlite3_finalize(stmt);
316 return PMINFO_R_ERROR;
319 _save_column_str(stmt, idx++, &info->text);
320 _save_column_str(stmt, idx++, &info->lang);
321 *icon = g_list_append(*icon, info);
324 sqlite3_finalize(stmt);
329 static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
330 const char *locale, GList **description)
332 static const char query_raw[] =
333 "SELECT package_description, package_locale "
334 "FROM package_localized_info "
335 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
342 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
344 LOGE("out of memory");
345 return PMINFO_R_ERROR;
348 ret = sqlite3_prepare_v2(db, query, strlen(query),
351 if (ret != SQLITE_OK) {
352 LOGE("prepare failed: %s", sqlite3_errmsg(db));
353 return PMINFO_R_ERROR;
356 while (sqlite3_step(stmt) == SQLITE_ROW) {
357 info = calloc(1, sizeof(description_x));
359 LOGE("out of memory");
360 sqlite3_finalize(stmt);
361 return PMINFO_R_ERROR;
364 _save_column_str(stmt, idx++, &info->text);
365 _save_column_str(stmt, idx++, &info->lang);
366 *description = g_list_append(*description, info);
369 sqlite3_finalize(stmt);
374 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
377 static const char query_raw[] =
378 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
384 query = sqlite3_mprintf(query_raw, pkgid);
386 LOGE("out of memory");
387 return PMINFO_R_ERROR;
390 ret = sqlite3_prepare_v2(db, query, strlen(query),
393 if (ret != SQLITE_OK) {
394 LOGE("prepare failed: %s", sqlite3_errmsg(db));
395 return PMINFO_R_ERROR;
398 while (sqlite3_step(stmt) == SQLITE_ROW) {
400 _save_column_str(stmt, 0, &privilege);
402 *privileges = g_list_append(*privileges,
403 (gpointer)privilege);
406 sqlite3_finalize(stmt);
411 static const char join_localized_info[] =
412 " LEFT OUTER JOIN package_localized_info"
413 " ON pi.package=package_localized_info.package"
414 " AND package_localized_info.package_locale=?";
415 static const char join_privilege_info[] =
416 " LEFT OUTER JOIN package_privilege_info"
417 " ON pi.package=package_privilege_info.package";
419 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
420 const char *locale, char **query, GList **bind_params)
423 char buf[MAX_QUERY_LEN] = { '\0' };
424 char buf2[MAX_QUERY_LEN] = { '\0' };
425 char *condition = NULL;
432 len += strlen(" WHERE 1=1 ");
433 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
434 for (list = filter->list; list; list = list->next) {
435 joined |= __get_filter_condition(list->data, &condition,
437 if (condition == NULL)
440 len += strlen(" AND ");
441 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
443 len += strlen(condition);
444 strncat(buf, condition, sizeof(buf) - len - 1);
449 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
450 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
451 len += strlen(join_localized_info);
452 *bind_params = g_list_append(*bind_params, strdup(locale));
454 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
455 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
456 len += strlen(join_privilege_info);
458 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
460 *query = strdup(buf2);
462 return PMINFO_R_ERROR;
467 static void __free_packages(gpointer data)
469 pkgmgrinfo_basic_free_package((package_x *)data);
472 static int __bind_params(sqlite3_stmt *stmt, GList *params)
474 GList *tmp_list = NULL;
478 if (stmt == NULL || params == NULL)
479 return PMINFO_R_EINVAL;
483 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
484 if (ret != SQLITE_OK)
485 return PMINFO_R_ERROR;
486 tmp_list = tmp_list->next;
492 static int _pkginfo_get_packages(uid_t uid, const char *locale,
493 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
495 static const char query_raw[] =
496 "SELECT DISTINCT pi.package, pi.package_version, "
497 "pi.install_location, pi.package_removable, "
498 "pi.package_preload, pi.package_readonly, pi.package_update, "
499 "pi.package_appsetting, pi.package_system, pi.package_type, "
500 "pi.package_size, pi.installed_time, pi.installed_storage, "
501 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
502 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
503 "pi.package_api_version, pi.package_support_disable, "
504 "pi.package_tep_name, pi.package_zip_mount_file "
505 "FROM package_info as pi ";
506 int ret = PMINFO_R_ERROR;
509 char *constraints = NULL;
510 char query[MAX_QUERY_LEN] = { '\0' };
511 package_x *info = NULL;
512 GList *bind_params = NULL;
515 pkgmgrinfo_filter_x *tmp_filter = NULL;
517 dbpath = getUserPkgParserDBPathUID(uid);
519 return PMINFO_R_ERROR;
521 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
522 if (ret != SQLITE_OK) {
523 _LOGD("failed to open db: %d", ret);
524 return PMINFO_R_ERROR;
527 if (filter != NULL) {
530 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
531 if (ret != PMINFO_R_OK) {
532 _LOGE("Failed to create filter");
533 return PMINFO_R_ERROR;
537 /* add package_disable='false' clause by default */
538 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
540 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
541 if (ret != PMINFO_R_OK) {
542 LOGE("Failed to get WHERE clause");
547 snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraints);
549 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
551 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
552 if (ret != SQLITE_OK) {
553 LOGE("prepare failed: %s", sqlite3_errmsg(db));
554 ret = PMINFO_R_ERROR;
558 ret = __bind_params(stmt, bind_params);
559 if (ret != SQLITE_OK) {
560 LOGE("Failed to bind parameters");
564 while (sqlite3_step(stmt) == SQLITE_ROW) {
565 info = calloc(1, sizeof(package_x));
567 LOGE("out of memory");
568 sqlite3_finalize(stmt);
569 sqlite3_close_v2(db);
570 return PMINFO_R_ERROR;
573 _save_column_str(stmt, idx++, &info->package);
574 if (g_hash_table_contains(packages,
575 (gconstpointer)info->package)) {
580 _save_column_str(stmt, idx++, &info->version);
581 _save_column_str(stmt, idx++, &info->installlocation);
582 _save_column_str(stmt, idx++, &info->removable);
583 _save_column_str(stmt, idx++, &info->preload);
584 _save_column_str(stmt, idx++, &info->readonly);
585 _save_column_str(stmt, idx++, &info->update);
586 _save_column_str(stmt, idx++, &info->appsetting);
587 _save_column_str(stmt, idx++, &info->system);
588 _save_column_str(stmt, idx++, &info->type);
589 _save_column_str(stmt, idx++, &info->package_size);
590 _save_column_str(stmt, idx++, &info->installed_time);
591 _save_column_str(stmt, idx++, &info->installed_storage);
592 _save_column_str(stmt, idx++, &info->storeclient_id);
593 _save_column_str(stmt, idx++, &info->mainapp_id);
594 _save_column_str(stmt, idx++, &info->package_url);
595 _save_column_str(stmt, idx++, &info->root_path);
596 _save_column_str(stmt, idx++, &info->csc_path);
597 _save_column_str(stmt, idx++, &info->nodisplay_setting);
598 _save_column_str(stmt, idx++, &info->api_version);
599 _save_column_str(stmt, idx++, &info->support_disable);
600 _save_column_str(stmt, idx++, &info->tep_name);
601 _save_column_str(stmt, idx++, &info->zip_mount_file);
602 info->for_all_users =
603 strdup((uid != GLOBAL_USER) ? "false" : "true");
605 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
606 if (_pkginfo_get_author(db, info->package,
608 pkgmgrinfo_basic_free_package(info);
609 sqlite3_finalize(stmt);
610 sqlite3_close_v2(db);
611 return PMINFO_R_ERROR;
615 if (flag & PMINFO_PKGINFO_GET_LABEL) {
616 if (_pkginfo_get_label(db, info->package, locale,
618 pkgmgrinfo_basic_free_package(info);
619 sqlite3_finalize(stmt);
620 sqlite3_close_v2(db);
621 return PMINFO_R_ERROR;
625 if (flag & PMINFO_PKGINFO_GET_ICON) {
626 if (_pkginfo_get_icon(db, info->package, locale,
628 pkgmgrinfo_basic_free_package(info);
629 sqlite3_finalize(stmt);
630 sqlite3_close_v2(db);
631 return PMINFO_R_ERROR;
635 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
636 if (_pkginfo_get_description(db, info->package, locale,
637 &info->description)) {
638 pkgmgrinfo_basic_free_package(info);
639 sqlite3_finalize(stmt);
640 sqlite3_close_v2(db);
641 return PMINFO_R_ERROR;
645 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
646 if (_pkginfo_get_privilege(db, info->package,
647 &info->privileges)) {
648 pkgmgrinfo_basic_free_package(info);
649 sqlite3_finalize(stmt);
650 sqlite3_close_v2(db);
651 return PMINFO_R_ERROR;
655 g_hash_table_insert(packages, (gpointer)info->package,
665 if (ret != PMINFO_R_OK && info != NULL)
666 pkgmgrinfo_basic_free_package(info);
669 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
671 g_list_free_full(bind_params, free);
672 sqlite3_close_v2(db);
673 sqlite3_finalize(stmt);
678 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
679 pkgmgrinfo_filter_x *filter, int flag,
680 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
685 pkgmgr_pkginfo_x info;
690 locale = _get_system_locale();
692 return PMINFO_R_ERROR;
694 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
698 return PMINFO_R_ERROR;
701 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
702 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
703 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
706 if (ret != PMINFO_R_OK) {
707 g_hash_table_destroy(list);
709 return PMINFO_R_ERROR;
712 g_hash_table_iter_init(&iter, list);
713 while (g_hash_table_iter_next(&iter, NULL, &value)) {
714 pkg = (package_x *)value;
717 info.locale = locale;
718 if (pkg_list_cb(&info, user_data) < 0)
722 g_hash_table_destroy(list);
728 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
729 pkgmgrinfo_pkginfo_h *handle)
734 pkgmgrinfo_pkginfo_filter_h filter;
735 pkgmgr_pkginfo_x *info;
737 if (pkgid == NULL || handle == NULL) {
738 LOGE("invalid parameter");
739 return PMINFO_R_EINVAL;
742 locale = _get_system_locale();
744 return PMINFO_R_ERROR;
746 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
747 if (ret != PMINFO_R_OK) {
752 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
753 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
754 if (ret != PMINFO_R_OK) {
755 pkgmgrinfo_pkginfo_filter_destroy(filter);
757 return PMINFO_R_ERROR;
760 list = g_hash_table_new(g_str_hash, g_str_equal);
762 pkgmgrinfo_pkginfo_filter_destroy(filter);
764 return PMINFO_R_ERROR;
767 ret = _pkginfo_get_packages(uid, locale, filter,
768 PMINFO_PKGINFO_GET_ALL, list);
769 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
770 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
771 PMINFO_PKGINFO_GET_ALL, list);
773 pkgmgrinfo_pkginfo_filter_destroy(filter);
774 if (ret != PMINFO_R_OK) {
775 g_hash_table_destroy(list);
780 if (!g_hash_table_size(list)) {
781 _LOGI("pkginfo for [%s] is not existed for user [%d]",
783 g_hash_table_destroy(list);
785 return PMINFO_R_ENOENT;
788 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
790 _LOGE("out of memory");
791 g_hash_table_destroy(list);
793 return PMINFO_R_ERROR;
797 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
798 info->locale = locale;
800 /* just free list only */
801 g_hash_table_destroy(list);
808 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
809 pkgmgrinfo_pkginfo_h *handle)
811 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
814 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
815 int flag, void *user_data, uid_t uid)
817 if (pkg_list_cb == NULL) {
818 LOGE("invalid parameter");
819 return PMINFO_R_EINVAL;
822 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
823 pkg_list_cb, user_data);
826 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
827 int flag, void *user_data)
829 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
830 user_data, _getuid());
833 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
834 void *user_data, uid_t uid)
836 if (pkg_list_cb == NULL) {
837 LOGE("invalid parameter");
838 return PMINFO_R_EINVAL;
841 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
842 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
845 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
848 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
852 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
854 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
856 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
857 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
859 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
860 return PMINFO_R_ERROR;
862 *pkg_name = (char *)info->pkg_info->package;
867 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
869 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
871 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
872 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
874 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
875 return PMINFO_R_ERROR;
877 *pkgid = (char *)info->pkg_info->package;
882 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
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(type == 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->type == NULL)
892 info->pkg_info->type = strdup("");
894 *type = (char *)info->pkg_info->type;
899 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
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(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
906 if (info->pkg_info == NULL)
907 return PMINFO_R_ERROR;
908 if (info->pkg_info->version == NULL)
909 info->pkg_info->version = strdup("");
911 *version = (char *)info->pkg_info->version;
916 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
918 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
920 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
921 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
923 if (info->pkg_info == NULL)
924 return PMINFO_R_ERROR;
925 if (info->pkg_info->api_version == NULL)
926 info->pkg_info->api_version = strdup("");
928 *api_version = (char *)info->pkg_info->api_version;
933 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
935 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
938 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
940 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
941 return PMINFO_R_ERROR;
943 *tep_name = (char *)info->pkg_info->tep_name;
948 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
950 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
952 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
953 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
955 if (info->pkg_info == NULL)
956 return PMINFO_R_ERROR;
957 if (info->pkg_info->zip_mount_file == NULL)
958 info->pkg_info->zip_mount_file = strdup("");
960 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
965 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
968 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
971 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
973 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
974 return PMINFO_R_ERROR;
976 val = (char *)info->pkg_info->installlocation;
977 if (strcmp(val, "internal-only") == 0)
978 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
979 else if (strcmp(val, "prefer-external") == 0)
980 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
982 *location = PMINFO_INSTALL_LOCATION_AUTO;
987 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
989 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
993 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
995 if (info->pkg_info == NULL)
996 return PMINFO_R_ERROR;
998 if (info->pkg_info->package_size == NULL) {
1001 _LOGE("out of memory");
1002 return PMINFO_R_ERROR;
1004 info->pkg_info->package_size = temp;
1008 *size = atoi((char *)info->pkg_info->package_size);
1013 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
1016 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1017 long long rw_size = 0;
1018 long long ro_size = 0;
1019 long long tmp_size = 0;
1020 long long total_size = 0;
1021 struct stat fileinfo;
1024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1025 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1027 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1029 return PMINFO_R_ERROR;
1032 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
1033 if (lstat(device_path, &fileinfo) == 0) {
1034 if (!S_ISLNK(fileinfo.st_mode)) {
1035 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1037 rw_size += tmp_size;
1041 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
1042 if (lstat(device_path, &fileinfo) == 0) {
1043 if (!S_ISLNK(fileinfo.st_mode)) {
1044 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1046 rw_size += tmp_size;
1050 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
1051 if (lstat(device_path, &fileinfo) == 0) {
1052 if (!S_ISLNK(fileinfo.st_mode)) {
1053 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1055 rw_size += tmp_size;
1059 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1060 if (lstat(device_path, &fileinfo) == 0) {
1061 if (!S_ISLNK(fileinfo.st_mode)) {
1062 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1064 rw_size += tmp_size;
1068 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
1069 if (lstat(device_path, &fileinfo) == 0) {
1070 if (!S_ISLNK(fileinfo.st_mode)) {
1071 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1073 rw_size += tmp_size;
1077 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
1078 if (lstat(device_path, &fileinfo) == 0) {
1079 if (!S_ISLNK(fileinfo.st_mode)) {
1080 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1082 rw_size += tmp_size;
1087 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
1088 if (lstat(device_path, &fileinfo) == 0) {
1089 if (!S_ISLNK(fileinfo.st_mode)) {
1090 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1092 ro_size += tmp_size;
1096 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
1097 if (lstat(device_path, &fileinfo) == 0) {
1098 if (!S_ISLNK(fileinfo.st_mode)) {
1099 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1101 ro_size += tmp_size;
1105 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
1106 if (lstat(device_path, &fileinfo) == 0) {
1107 if (!S_ISLNK(fileinfo.st_mode)) {
1108 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1110 ro_size += tmp_size;
1114 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
1115 if (lstat(device_path, &fileinfo) == 0) {
1116 if (!S_ISLNK(fileinfo.st_mode)) {
1117 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1119 ro_size += tmp_size;
1123 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
1124 if (lstat(device_path, &fileinfo) == 0) {
1125 if (!S_ISLNK(fileinfo.st_mode)) {
1126 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1128 ro_size += tmp_size;
1132 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
1133 if (lstat(device_path, &fileinfo) == 0) {
1134 if (!S_ISLNK(fileinfo.st_mode)) {
1135 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1137 ro_size += tmp_size;
1142 total_size = rw_size + ro_size;
1143 *size = (int)total_size;
1148 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1151 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1152 long long total_size = 0;
1154 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1155 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1157 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1158 return PMINFO_R_ERROR;
1160 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1161 if (access(device_path, R_OK) == 0)
1162 total_size = _pkgmgr_calculate_dir_size(device_path);
1164 return PMINFO_R_ERROR;
1166 *size = (int)total_size;
1171 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1176 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1179 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1181 locale = info->locale;
1182 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1184 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1185 return PMINFO_R_ERROR;
1187 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1188 ptr = (icon_x *)tmp->data;
1189 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1190 strcmp(ptr->lang, locale))
1192 *icon = (char *)ptr->text;
1196 locale = DEFAULT_LOCALE;
1197 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1198 ptr = (icon_x *)tmp->data;
1199 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1200 strcmp(ptr->lang, locale))
1202 *icon = (char *)ptr->text;
1211 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1216 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1219 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1221 locale = info->locale;
1222 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1224 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1225 return PMINFO_R_ERROR;
1227 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1228 ptr = (label_x *)tmp->data;
1229 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1230 strcmp(ptr->lang, locale))
1232 *label = (char *)ptr->text;
1236 locale = DEFAULT_LOCALE;
1237 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1238 ptr = (label_x *)tmp->data;
1239 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1240 strcmp(ptr->lang, locale))
1242 *label = (char *)ptr->text;
1251 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1256 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1258 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1259 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1261 locale = info->locale;
1262 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1264 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1265 return PMINFO_R_ERROR;
1267 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1268 ptr = (description_x *)tmp->data;
1269 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1270 strcmp(ptr->lang, locale))
1272 *description = (char *)ptr->text;
1276 locale = DEFAULT_LOCALE;
1277 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1278 ptr = (description_x *)tmp->data;
1279 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1280 strcmp(ptr->lang, locale))
1282 *description = (char *)ptr->text;
1291 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1293 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1297 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1299 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1300 return PMINFO_R_ERROR;
1302 author = (author_x *)info->pkg_info->author->data;
1304 return PMINFO_R_ERROR;
1305 if (author->text == NULL)
1306 author->text = strdup("");
1308 *author_name = (char *)author->text;
1313 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1315 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1319 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1321 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1322 return PMINFO_R_ERROR;
1324 author = (author_x *)info->pkg_info->author->data;
1326 return PMINFO_R_ERROR;
1327 if (author->email == NULL)
1328 author->email = strdup("");
1330 *author_email = (char *)author->email;
1335 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1337 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1341 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1343 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1344 return PMINFO_R_ERROR;
1346 author = (author_x *)info->pkg_info->author->data;
1348 return PMINFO_R_ERROR;
1349 if (author->href == NULL)
1350 author->href = strdup("");
1352 *author_href = (char *)author->href;
1357 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1359 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1361 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1362 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1364 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1365 return PMINFO_R_ERROR;
1367 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1368 *storage = PMINFO_INTERNAL_STORAGE;
1369 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1370 *storage = PMINFO_EXTERNAL_STORAGE;
1372 return PMINFO_R_ERROR;
1377 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1379 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1382 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1384 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1385 return PMINFO_R_ERROR;
1387 *installed_time = atoi(info->pkg_info->installed_time);
1392 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1394 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1397 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1399 if (info->pkg_info == NULL)
1400 return PMINFO_R_ERROR;
1401 if (info->pkg_info->storeclient_id == NULL)
1402 info->pkg_info->storeclient_id = strdup("");
1404 *storeclientid = (char *)info->pkg_info->storeclient_id;
1409 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1411 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1414 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1416 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1417 return PMINFO_R_ERROR;
1419 *mainappid = (char *)info->pkg_info->mainapp_id;
1424 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1426 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1429 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1431 if (info->pkg_info == NULL)
1432 return PMINFO_R_ERROR;
1433 if (info->pkg_info->package_url == NULL)
1434 info->pkg_info->package_url = strdup("");
1436 *url = (char *)info->pkg_info->package_url;
1441 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1443 const char *val = NULL;
1444 const xmlChar *node;
1445 xmlTextReaderPtr reader;
1446 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1447 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1450 reader = xmlReaderForFile(manifest, NULL, 0);
1453 if (__child_element(reader, -1)) {
1454 node = xmlTextReaderConstName(reader);
1456 _LOGE("xmlTextReaderConstName value is NULL\n");
1457 xmlFreeTextReader(reader);
1459 return PMINFO_R_ERROR;
1462 if (!strcmp(ASC_CHAR(node), "manifest")) {
1463 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1464 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1470 _LOGE("package size is not specified\n");
1471 xmlFreeTextReader(reader);
1473 return PMINFO_R_ERROR;
1476 _LOGE("Unable to create xml reader\n");
1477 xmlFreeTextReader(reader);
1479 return PMINFO_R_ERROR;
1483 _LOGE("xmlReaderForFile value is NULL\n");
1485 return PMINFO_R_ERROR;
1488 xmlFreeTextReader(reader);
1494 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1496 const char *val = NULL;
1497 const xmlChar *node;
1498 xmlTextReaderPtr reader;
1499 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1500 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1503 reader = xmlReaderForFile(manifest, NULL, 0);
1506 if ( __child_element(reader, -1)) {
1507 node = xmlTextReaderConstName(reader);
1509 _LOGE("xmlTextReaderConstName value is NULL\n");
1510 xmlFreeTextReader(reader);
1512 return PMINFO_R_ERROR;
1515 if (!strcmp(ASC_CHAR(node), "manifest")) {
1516 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1517 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1520 if (strcmp(val, "internal-only") == 0)
1521 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1522 else if (strcmp(val, "prefer-external") == 0)
1523 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1525 *location = PMINFO_INSTALL_LOCATION_AUTO;
1528 _LOGE("Unable to create xml reader\n");
1529 xmlFreeTextReader(reader);
1531 return PMINFO_R_ERROR;
1535 _LOGE("xmlReaderForFile value is NULL\n");
1537 return PMINFO_R_ERROR;
1540 xmlFreeTextReader(reader);
1547 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1549 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1552 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1554 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1555 return PMINFO_R_ERROR;
1557 *path = (char *)info->pkg_info->root_path;
1562 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1564 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1567 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1569 if (info->pkg_info == NULL)
1570 return PMINFO_R_ERROR;
1571 if (info->pkg_info->csc_path == NULL)
1572 info->pkg_info->csc_path = strdup("");
1574 *path = (char *)info->pkg_info->csc_path;
1580 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1583 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1585 #if 0 //smack issue occured, check later
1587 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1589 _LOGD("invalid func parameters\n");
1590 return PMINFO_R_ERROR;
1592 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1595 char app_mmc_path[FILENAME_MAX] = { 0, };
1596 char app_dir_path[FILENAME_MAX] = { 0, };
1597 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1598 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1599 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1600 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1602 /*check whether application is in external memory or not */
1603 fp = fopen(app_mmc_path, "r");
1605 _LOGD(" app path in external memory not accesible\n");
1610 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1614 /*check whether application is in internal or not */
1615 fp = fopen(app_dir_path, "r");
1617 _LOGD(" app path in internal memory not accesible\n");
1619 return PMINFO_R_ERROR;
1622 /*check whether the application is installed in SD card
1623 but SD card is not present*/
1624 fp = fopen(app_mmc_internal_path, "r");
1627 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1632 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1637 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1644 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1646 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1649 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1651 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1652 return PMINFO_R_ERROR;
1654 *removable = _get_bool_value(info->pkg_info->removable);
1659 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1662 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1665 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1667 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1668 return PMINFO_R_ERROR;
1670 val = (char *)info->pkg_info->installlocation;
1671 if (strcmp(val, "internal-only") == 0)
1673 else if (strcmp(val, "prefer-external") == 0)
1681 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1683 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1686 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1688 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1689 return PMINFO_R_ERROR;
1691 *preload = _get_bool_value(info->pkg_info->preload);
1696 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1698 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1701 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1703 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1704 return PMINFO_R_ERROR;
1706 *system = _get_bool_value(info->pkg_info->system);
1711 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1713 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1715 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1716 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1718 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1719 return PMINFO_R_ERROR;
1721 *readonly = _get_bool_value(info->pkg_info->readonly);
1726 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1728 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1730 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1731 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1733 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1734 return PMINFO_R_ERROR;
1736 *update = _get_bool_value(info->pkg_info->update);
1741 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1743 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1746 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1748 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1749 return PMINFO_R_ERROR;
1751 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1756 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1758 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1760 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1761 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1763 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1764 return PMINFO_R_ERROR;
1766 *global = _get_bool_value(info->pkg_info->for_all_users);
1771 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1773 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1776 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1778 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1782 __cleanup_pkginfo(info);
1787 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1789 pkgmgrinfo_filter_x *filter;
1791 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1793 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1794 if (filter == NULL) {
1795 _LOGE("Out of Memory!!!");
1796 return PMINFO_R_ERROR;
1804 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1806 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1811 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1812 g_slist_free(filter->list);
1820 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1821 const char *property, const int value)
1823 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1827 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1828 pkgmgrinfo_node_x *node;
1830 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1831 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1833 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1834 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1835 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1836 _LOGE("Invalid Integer Property\n");
1837 return PMINFO_R_EINVAL;
1839 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1841 _LOGE("Out of Memory!!!\n");
1842 return PMINFO_R_ERROR;
1844 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1845 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1847 _LOGE("Out of Memory\n");
1849 return PMINFO_R_ERROR;
1853 /*If API is called multiple times for same property, we should override the previous values.
1854 Last value set will be used for filtering.*/
1855 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1857 filter->list = g_slist_delete_link(filter->list, link);
1858 filter->list = g_slist_append(filter->list, (gpointer)node);
1863 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1864 const char *property, const bool value)
1869 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1870 pkgmgrinfo_node_x *node;
1872 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1873 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1875 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1876 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1877 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1878 _LOGE("Invalid Boolean Property\n");
1879 return PMINFO_R_EINVAL;
1881 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1883 _LOGE("Out of Memory!!!\n");
1884 return PMINFO_R_ERROR;
1887 val = strndup("true", 4);
1889 val = strndup("false", 5);
1891 _LOGE("Out of Memory\n");
1893 return PMINFO_R_ERROR;
1897 /*If API is called multiple times for same property, we should override the previous values.
1898 Last value set will be used for filtering.*/
1899 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1901 filter->list = g_slist_delete_link(filter->list, link);
1902 filter->list = g_slist_append(filter->list, (gpointer)node);
1907 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1908 const char *property, const char *value)
1913 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1914 pkgmgrinfo_node_x *node;
1916 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1917 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1918 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1920 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1921 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1922 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1923 _LOGE("Invalid String Property\n");
1924 return PMINFO_R_EINVAL;
1926 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1928 _LOGE("Out of Memory!!!\n");
1929 return PMINFO_R_ERROR;
1931 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1932 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1933 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1934 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1935 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1936 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1937 else if (strcmp(value, "installed_internal") == 0)
1938 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1939 else if (strcmp(value, "installed_external") == 0)
1940 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1942 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1944 _LOGE("Out of Memory\n");
1946 return PMINFO_R_ERROR;
1950 /*If API is called multiple times for same property, we should override the previous values.
1951 Last value set will be used for filtering.*/
1952 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1954 filter->list = g_slist_delete_link(filter->list, link);
1955 filter->list = g_slist_append(filter->list, (gpointer)node);
1960 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1964 GHashTable *list = NULL;
1966 if (handle == NULL || count == NULL) {
1967 _LOGE("invalid parameter");
1968 return PMINFO_R_EINVAL;
1971 locale = _get_system_locale();
1973 return PMINFO_R_ERROR;
1975 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1979 return PMINFO_R_ERROR;
1982 ret = _pkginfo_get_packages(uid, locale,
1983 (pkgmgrinfo_filter_x *)handle, 0, list);
1984 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1985 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1988 if (ret != PMINFO_R_OK) {
1989 g_hash_table_destroy(list);
1991 return PMINFO_R_ERROR;
1994 *count = g_hash_table_size(list);
1996 g_hash_table_destroy(list);
2002 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
2004 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
2007 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
2008 pkgmgrinfo_pkginfo_filter_h handle,
2009 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
2011 if (handle == NULL || pkg_cb == NULL) {
2012 LOGE("invalid parameter");
2013 return PMINFO_R_EINVAL;
2016 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
2017 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
2020 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
2021 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2023 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2026 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2027 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2029 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2030 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2032 const char *privilege;
2034 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2036 if (info->pkg_info == NULL)
2037 return PMINFO_R_ERROR;
2039 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2040 privilege = (const char *)tmp->data;
2041 if (privilege == NULL)
2043 ret = privilege_func(privilege, user_data);