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 (!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;
991 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
992 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
994 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
995 return PMINFO_R_ERROR;
997 *size = atoi((char *)info->pkg_info->package_size);
1002 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
1005 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1006 long long rw_size = 0;
1007 long long ro_size = 0;
1008 long long tmp_size = 0;
1009 long long total_size = 0;
1010 struct stat fileinfo;
1013 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1014 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1016 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1018 return PMINFO_R_ERROR;
1021 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
1022 if (lstat(device_path, &fileinfo) == 0) {
1023 if (!S_ISLNK(fileinfo.st_mode)) {
1024 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1026 rw_size += tmp_size;
1030 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
1031 if (lstat(device_path, &fileinfo) == 0) {
1032 if (!S_ISLNK(fileinfo.st_mode)) {
1033 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1035 rw_size += tmp_size;
1039 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
1040 if (lstat(device_path, &fileinfo) == 0) {
1041 if (!S_ISLNK(fileinfo.st_mode)) {
1042 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1044 rw_size += tmp_size;
1048 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1049 if (lstat(device_path, &fileinfo) == 0) {
1050 if (!S_ISLNK(fileinfo.st_mode)) {
1051 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1053 rw_size += tmp_size;
1057 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
1058 if (lstat(device_path, &fileinfo) == 0) {
1059 if (!S_ISLNK(fileinfo.st_mode)) {
1060 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1062 rw_size += tmp_size;
1066 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
1067 if (lstat(device_path, &fileinfo) == 0) {
1068 if (!S_ISLNK(fileinfo.st_mode)) {
1069 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1071 rw_size += tmp_size;
1076 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
1077 if (lstat(device_path, &fileinfo) == 0) {
1078 if (!S_ISLNK(fileinfo.st_mode)) {
1079 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1081 ro_size += tmp_size;
1085 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
1086 if (lstat(device_path, &fileinfo) == 0) {
1087 if (!S_ISLNK(fileinfo.st_mode)) {
1088 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1090 ro_size += tmp_size;
1094 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
1095 if (lstat(device_path, &fileinfo) == 0) {
1096 if (!S_ISLNK(fileinfo.st_mode)) {
1097 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1099 ro_size += tmp_size;
1103 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
1104 if (lstat(device_path, &fileinfo) == 0) {
1105 if (!S_ISLNK(fileinfo.st_mode)) {
1106 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1108 ro_size += tmp_size;
1112 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
1113 if (lstat(device_path, &fileinfo) == 0) {
1114 if (!S_ISLNK(fileinfo.st_mode)) {
1115 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1117 ro_size += tmp_size;
1121 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
1122 if (lstat(device_path, &fileinfo) == 0) {
1123 if (!S_ISLNK(fileinfo.st_mode)) {
1124 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1126 ro_size += tmp_size;
1131 total_size = rw_size + ro_size;
1132 *size = (int)total_size;
1137 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1140 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1141 long long total_size = 0;
1143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1144 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1146 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1147 return PMINFO_R_ERROR;
1149 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1150 if (access(device_path, R_OK) == 0)
1151 total_size = _pkgmgr_calculate_dir_size(device_path);
1153 return PMINFO_R_ERROR;
1155 *size = (int)total_size;
1160 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1168 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1170 locale = info->locale;
1171 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1173 if (info->pkg_info == NULL)
1174 return PMINFO_R_ERROR;
1176 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1177 ptr = (icon_x *)tmp->data;
1178 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1179 !strcasecmp(ptr->text, "(null)") ||
1180 strcmp(ptr->lang, locale))
1182 *icon = (char *)ptr->text;
1186 locale = DEFAULT_LOCALE;
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 return PMINFO_R_ERROR;
1199 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1204 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1207 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1209 locale = info->locale;
1210 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1212 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1213 ptr = (label_x *)tmp->data;
1214 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1215 strcmp(ptr->lang, locale))
1217 *label = (char *)ptr->text;
1221 locale = DEFAULT_LOCALE;
1222 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1223 ptr = (label_x *)tmp->data;
1224 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1225 strcmp(ptr->lang, locale))
1227 *label = (char *)ptr->text;
1231 return PMINFO_R_ERROR;
1234 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1239 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1242 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1244 locale = info->locale;
1245 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1247 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1248 ptr = (description_x *)tmp->data;
1249 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1250 strcmp(ptr->lang, locale))
1252 *description = (char *)ptr->text;
1256 locale = DEFAULT_LOCALE;
1257 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1258 ptr = (description_x *)tmp->data;
1259 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1260 strcmp(ptr->lang, locale))
1262 *description = (char *)ptr->text;
1266 return PMINFO_R_ERROR;
1269 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1271 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1274 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1275 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1277 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1278 return PMINFO_R_ERROR;
1280 author = (author_x *)info->pkg_info->author->data;
1282 return PMINFO_R_ERROR;
1283 if (author->text == NULL)
1284 author->text = strdup("");
1286 *author_name = (char *)author->text;
1291 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
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_email == 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->email == NULL)
1306 author->email = strdup("");
1308 *author_email = (char *)author->email;
1313 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
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_href == 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->href == NULL)
1328 author->href = strdup("");
1330 *author_href = (char *)author->href;
1335 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1337 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1339 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1340 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1342 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1343 return PMINFO_R_ERROR;
1345 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1346 *storage = PMINFO_INTERNAL_STORAGE;
1347 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1348 *storage = PMINFO_EXTERNAL_STORAGE;
1350 return PMINFO_R_ERROR;
1355 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1357 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1359 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1360 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1362 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1363 return PMINFO_R_ERROR;
1365 *installed_time = atoi(info->pkg_info->installed_time);
1370 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1372 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1375 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1377 if (info->pkg_info == NULL)
1378 return PMINFO_R_ERROR;
1379 if (info->pkg_info->storeclient_id == NULL)
1380 info->pkg_info->storeclient_id = strdup("");
1382 *storeclientid = (char *)info->pkg_info->storeclient_id;
1387 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1389 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1392 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1394 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1395 return PMINFO_R_ERROR;
1397 *mainappid = (char *)info->pkg_info->mainapp_id;
1402 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1404 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1406 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1407 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1409 if (info->pkg_info == NULL)
1410 return PMINFO_R_ERROR;
1411 if (info->pkg_info->package_url == NULL)
1412 info->pkg_info->package_url = strdup("");
1414 *url = (char *)info->pkg_info->package_url;
1419 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1421 const char *val = NULL;
1422 const xmlChar *node;
1423 xmlTextReaderPtr reader;
1424 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1425 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1428 reader = xmlReaderForFile(manifest, NULL, 0);
1431 if (__child_element(reader, -1)) {
1432 node = xmlTextReaderConstName(reader);
1434 _LOGE("xmlTextReaderConstName value is NULL\n");
1435 xmlFreeTextReader(reader);
1437 return PMINFO_R_ERROR;
1440 if (!strcmp(ASC_CHAR(node), "manifest")) {
1441 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1442 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1448 _LOGE("package size is not specified\n");
1449 xmlFreeTextReader(reader);
1451 return PMINFO_R_ERROR;
1454 _LOGE("Unable to create xml reader\n");
1455 xmlFreeTextReader(reader);
1457 return PMINFO_R_ERROR;
1461 _LOGE("xmlReaderForFile value is NULL\n");
1463 return PMINFO_R_ERROR;
1466 xmlFreeTextReader(reader);
1472 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1474 const char *val = NULL;
1475 const xmlChar *node;
1476 xmlTextReaderPtr reader;
1477 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1478 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1481 reader = xmlReaderForFile(manifest, NULL, 0);
1484 if ( __child_element(reader, -1)) {
1485 node = xmlTextReaderConstName(reader);
1487 _LOGE("xmlTextReaderConstName value is NULL\n");
1488 xmlFreeTextReader(reader);
1490 return PMINFO_R_ERROR;
1493 if (!strcmp(ASC_CHAR(node), "manifest")) {
1494 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1495 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1498 if (strcmp(val, "internal-only") == 0)
1499 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1500 else if (strcmp(val, "prefer-external") == 0)
1501 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1503 *location = PMINFO_INSTALL_LOCATION_AUTO;
1506 _LOGE("Unable to create xml reader\n");
1507 xmlFreeTextReader(reader);
1509 return PMINFO_R_ERROR;
1513 _LOGE("xmlReaderForFile value is NULL\n");
1515 return PMINFO_R_ERROR;
1518 xmlFreeTextReader(reader);
1525 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1527 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1529 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1530 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1532 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1533 return PMINFO_R_ERROR;
1535 *path = (char *)info->pkg_info->root_path;
1540 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1542 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1545 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1547 if (info->pkg_info == NULL)
1548 return PMINFO_R_ERROR;
1549 if (info->pkg_info->csc_path == NULL)
1550 info->pkg_info->csc_path = strdup("");
1552 *path = (char *)info->pkg_info->csc_path;
1558 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1560 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1561 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1563 #if 0 //smack issue occured, check later
1565 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1567 _LOGD("invalid func parameters\n");
1568 return PMINFO_R_ERROR;
1570 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1573 char app_mmc_path[FILENAME_MAX] = { 0, };
1574 char app_dir_path[FILENAME_MAX] = { 0, };
1575 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1576 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1577 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1578 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1580 /*check whether application is in external memory or not */
1581 fp = fopen(app_mmc_path, "r");
1583 _LOGD(" app path in external memory not accesible\n");
1588 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1592 /*check whether application is in internal or not */
1593 fp = fopen(app_dir_path, "r");
1595 _LOGD(" app path in internal memory not accesible\n");
1597 return PMINFO_R_ERROR;
1600 /*check whether the application is installed in SD card
1601 but SD card is not present*/
1602 fp = fopen(app_mmc_internal_path, "r");
1605 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1610 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1615 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1622 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1624 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1627 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1629 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1630 return PMINFO_R_ERROR;
1632 *removable = _get_bool_value(info->pkg_info->removable);
1637 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1640 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1643 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1645 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1646 return PMINFO_R_ERROR;
1648 val = (char *)info->pkg_info->installlocation;
1649 if (strcmp(val, "internal-only") == 0)
1651 else if (strcmp(val, "prefer-external") == 0)
1659 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1661 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1663 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1664 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1666 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1667 return PMINFO_R_ERROR;
1669 *preload = _get_bool_value(info->pkg_info->preload);
1674 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1676 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1678 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1679 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1681 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1682 return PMINFO_R_ERROR;
1684 *system = _get_bool_value(info->pkg_info->system);
1689 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1691 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1693 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1694 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1696 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1697 return PMINFO_R_ERROR;
1699 *readonly = _get_bool_value(info->pkg_info->readonly);
1704 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1706 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1708 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1709 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1711 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1712 return PMINFO_R_ERROR;
1714 *update = _get_bool_value(info->pkg_info->update);
1719 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1721 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1723 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1724 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1726 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1727 return PMINFO_R_ERROR;
1729 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1734 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1736 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1738 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1739 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1741 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1742 return PMINFO_R_ERROR;
1744 *global = _get_bool_value(info->pkg_info->for_all_users);
1749 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1751 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1754 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1756 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1758 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1760 __cleanup_pkginfo(info);
1765 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1767 pkgmgrinfo_filter_x *filter;
1769 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1771 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1772 if (filter == NULL) {
1773 _LOGE("Out of Memory!!!");
1774 return PMINFO_R_ERROR;
1782 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1784 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1786 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1789 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1790 g_slist_free(filter->list);
1798 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1799 const char *property, const int value)
1801 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1805 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1806 pkgmgrinfo_node_x *node;
1808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1809 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1811 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1812 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1813 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1814 _LOGE("Invalid Integer Property\n");
1815 return PMINFO_R_EINVAL;
1817 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1819 _LOGE("Out of Memory!!!\n");
1820 return PMINFO_R_ERROR;
1822 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1823 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1825 _LOGE("Out of Memory\n");
1827 return PMINFO_R_ERROR;
1831 /*If API is called multiple times for same property, we should override the previous values.
1832 Last value set will be used for filtering.*/
1833 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1835 filter->list = g_slist_delete_link(filter->list, link);
1836 filter->list = g_slist_append(filter->list, (gpointer)node);
1841 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1842 const char *property, const bool value)
1847 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1848 pkgmgrinfo_node_x *node;
1850 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1851 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1853 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1854 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1855 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1856 _LOGE("Invalid Boolean Property\n");
1857 return PMINFO_R_EINVAL;
1859 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1861 _LOGE("Out of Memory!!!\n");
1862 return PMINFO_R_ERROR;
1865 val = strndup("true", 4);
1867 val = strndup("false", 5);
1869 _LOGE("Out of Memory\n");
1871 return PMINFO_R_ERROR;
1875 /*If API is called multiple times for same property, we should override the previous values.
1876 Last value set will be used for filtering.*/
1877 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1879 filter->list = g_slist_delete_link(filter->list, link);
1880 filter->list = g_slist_append(filter->list, (gpointer)node);
1885 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1886 const char *property, const char *value)
1891 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1892 pkgmgrinfo_node_x *node;
1894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1895 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1896 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1898 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1899 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1900 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1901 _LOGE("Invalid String Property\n");
1902 return PMINFO_R_EINVAL;
1904 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1906 _LOGE("Out of Memory!!!\n");
1907 return PMINFO_R_ERROR;
1909 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1910 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1911 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1912 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1913 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1914 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1915 else if (strcmp(value, "installed_internal") == 0)
1916 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1917 else if (strcmp(value, "installed_external") == 0)
1918 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1920 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1922 _LOGE("Out of Memory\n");
1924 return PMINFO_R_ERROR;
1928 /*If API is called multiple times for same property, we should override the previous values.
1929 Last value set will be used for filtering.*/
1930 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1932 filter->list = g_slist_delete_link(filter->list, link);
1933 filter->list = g_slist_append(filter->list, (gpointer)node);
1938 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1942 GHashTable *list = NULL;
1944 if (handle == NULL || count == NULL) {
1945 _LOGE("invalid parameter");
1946 return PMINFO_R_EINVAL;
1949 locale = _get_system_locale();
1951 return PMINFO_R_ERROR;
1953 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1957 return PMINFO_R_ERROR;
1960 ret = _pkginfo_get_packages(uid, locale,
1961 (pkgmgrinfo_filter_x *)handle, 0, list);
1962 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1963 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1966 if (ret != PMINFO_R_OK) {
1967 g_hash_table_destroy(list);
1969 return PMINFO_R_ERROR;
1972 *count = g_hash_table_size(list);
1974 g_hash_table_destroy(list);
1980 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1982 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1985 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1986 pkgmgrinfo_pkginfo_filter_h handle,
1987 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1989 if (handle == NULL || pkg_cb == NULL) {
1990 LOGE("invalid parameter");
1991 return PMINFO_R_EINVAL;
1994 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1995 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1998 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1999 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2001 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2004 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2005 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2007 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2008 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2010 const char *privilege;
2012 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2014 if (info->pkg_info == NULL)
2015 return PMINFO_R_ERROR;
2017 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2018 privilege = (const char *)tmp->data;
2019 if (privilege == NULL)
2021 ret = privilege_func(privilege, user_data);