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)
53 else if (!strcasecmp(str, "true"))
59 static gint __compare_func(gconstpointer data1, gconstpointer data2)
61 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
62 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
63 if (node1->prop == node2->prop)
65 else if (node1->prop > node2->prop)
71 static void __destroy_each_node(gpointer data, gpointer user_data)
74 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
87 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
91 free((void *)data->locale);
95 pkgmgrinfo_basic_free_package(data->pkg_info);
101 static int __child_element(xmlTextReaderPtr reader, int depth)
103 int ret = xmlTextReaderRead(reader);
104 int cur = xmlTextReaderDepth(reader);
107 switch (xmlTextReaderNodeType(reader)) {
108 case XML_READER_TYPE_ELEMENT:
109 if (cur == depth + 1)
112 case XML_READER_TYPE_TEXT:
113 /*text is handled by each function separately*/
114 if (cur == depth + 1)
117 case XML_READER_TYPE_END_ELEMENT:
126 ret = xmlTextReaderRead(reader);
127 cur = xmlTextReaderDepth(reader);
132 long long _pkgmgr_calculate_dir_size(char *dirname)
136 int q = 0; /*quotient*/
137 int r = 0; /*remainder*/
139 struct dirent ep, *result;
140 struct stat fileinfo;
141 char abs_filename[FILENAME_MAX] = { 0, };
142 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
144 dp = opendir(dirname);
146 _LOGE("Couldn't open the directory\n");
150 for (ret = readdir_r(dp, &ep, &result);
151 ret == 0 && result != NULL;
152 ret = readdir_r(dp, &ep, &result)) {
153 if (!strcmp(ep.d_name, ".") ||
154 !strcmp(ep.d_name, "..")) {
157 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
159 if (lstat(abs_filename, &fileinfo) < 0)
160 perror(abs_filename);
162 if (S_ISDIR(fileinfo.st_mode)) {
163 total += fileinfo.st_size;
164 if (strcmp(ep.d_name, ".")
165 && strcmp(ep.d_name, "..")) {
166 ret = _pkgmgr_calculate_dir_size
170 } else if (S_ISLNK(fileinfo.st_mode)) {
173 /*It is a file. Calculate the actual
174 size occupied (in terms of 4096 blocks)*/
175 q = (fileinfo.st_size / BLOCK_SIZE);
176 r = (fileinfo.st_size % BLOCK_SIZE);
180 total += q * BLOCK_SIZE;
189 static int _pkginfo_get_author(sqlite3 *db, const char *pkgid,
192 static const char query_raw[] =
193 "SELECT author_name, author_email, author_href "
194 "FROM package_info WHERE package=%Q";
201 query = sqlite3_mprintf(query_raw, pkgid);
203 LOGE("out of memory");
204 return PMINFO_R_ERROR;
207 ret = sqlite3_prepare_v2(db, query, strlen(query),
210 if (ret != SQLITE_OK) {
211 LOGE("prepare failed: %s", sqlite3_errmsg(db));
212 return PMINFO_R_ERROR;
215 if (sqlite3_step(stmt) == SQLITE_ERROR) {
216 LOGE("step error: %s", sqlite3_errmsg(db));
217 sqlite3_finalize(stmt);
218 return PMINFO_R_ERROR;
221 /* one author per one package */
222 info = calloc(1, sizeof(author_x));
224 LOGE("out of memory");
225 sqlite3_finalize(stmt);
226 return PMINFO_R_ERROR;
229 _save_column_str(stmt, idx++, &info->text);
230 _save_column_str(stmt, idx++, &info->email);
231 _save_column_str(stmt, idx++, &info->href);
234 *author = g_list_append(*author, info);
236 sqlite3_finalize(stmt);
241 static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
242 const char *locale, GList **label)
244 static const char query_raw[] =
245 "SELECT package_label, package_locale "
246 "FROM package_localized_info "
247 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
254 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
256 LOGE("out of memory");
257 return PMINFO_R_ERROR;
260 ret = sqlite3_prepare_v2(db, query, strlen(query),
263 if (ret != SQLITE_OK) {
264 LOGE("prepare failed: %s", sqlite3_errmsg(db));
265 return PMINFO_R_ERROR;
268 while (sqlite3_step(stmt) == SQLITE_ROW) {
269 info = calloc(1, sizeof(label_x));
271 LOGE("out of memory");
272 sqlite3_finalize(stmt);
273 return PMINFO_R_ERROR;
276 _save_column_str(stmt, idx++, &info->text);
277 _save_column_str(stmt, idx++, &info->lang);
278 *label = g_list_append(*label, info);
281 sqlite3_finalize(stmt);
286 static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
289 static const char query_raw[] =
290 "SELECT package_icon, package_locale "
291 "FROM package_localized_info "
292 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
299 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
301 LOGE("out of memory");
302 return PMINFO_R_ERROR;
305 ret = sqlite3_prepare_v2(db, query, strlen(query),
308 if (ret != SQLITE_OK) {
309 LOGE("prepare failed: %s", sqlite3_errmsg(db));
310 return PMINFO_R_ERROR;
313 while (sqlite3_step(stmt) == SQLITE_ROW) {
314 info = calloc(1, sizeof(icon_x));
316 LOGE("out of memory");
317 sqlite3_finalize(stmt);
318 return PMINFO_R_ERROR;
321 _save_column_str(stmt, idx++, &info->text);
322 _save_column_str(stmt, idx++, &info->lang);
323 *icon = g_list_append(*icon, info);
326 sqlite3_finalize(stmt);
331 static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
332 const char *locale, GList **description)
334 static const char query_raw[] =
335 "SELECT package_description, package_locale "
336 "FROM package_localized_info "
337 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
344 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
346 LOGE("out of memory");
347 return PMINFO_R_ERROR;
350 ret = sqlite3_prepare_v2(db, query, strlen(query),
353 if (ret != SQLITE_OK) {
354 LOGE("prepare failed: %s", sqlite3_errmsg(db));
355 return PMINFO_R_ERROR;
358 while (sqlite3_step(stmt) == SQLITE_ROW) {
359 info = calloc(1, sizeof(description_x));
361 LOGE("out of memory");
362 sqlite3_finalize(stmt);
363 return PMINFO_R_ERROR;
366 _save_column_str(stmt, idx++, &info->text);
367 _save_column_str(stmt, idx++, &info->lang);
368 *description = g_list_append(*description, info);
371 sqlite3_finalize(stmt);
376 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
379 static const char query_raw[] =
380 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
386 query = sqlite3_mprintf(query_raw, pkgid);
388 LOGE("out of memory");
389 return PMINFO_R_ERROR;
392 ret = sqlite3_prepare_v2(db, query, strlen(query),
395 if (ret != SQLITE_OK) {
396 LOGE("prepare failed: %s", sqlite3_errmsg(db));
397 return PMINFO_R_ERROR;
400 while (sqlite3_step(stmt) == SQLITE_ROW) {
402 _save_column_str(stmt, 0, &privilege);
404 *privileges = g_list_append(*privileges,
405 (gpointer)privilege);
408 sqlite3_finalize(stmt);
413 static const char join_localized_info[] =
414 " LEFT OUTER JOIN package_localized_info"
415 " ON pi.package=package_localized_info.package"
416 " AND package_localized_info.package_locale=?";
417 static const char join_privilege_info[] =
418 " LEFT OUTER JOIN package_privilege_info"
419 " ON pi.package=package_privilege_info.package";
421 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
422 const char *locale, char **query, GList **bind_params)
425 char buf[MAX_QUERY_LEN] = { '\0' };
426 char buf2[MAX_QUERY_LEN] = { '\0' };
427 char *condition = NULL;
434 len += strlen(" WHERE 1=1 ");
435 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
436 for (list = filter->list; list; list = list->next) {
437 joined |= __get_filter_condition(list->data, &condition,
439 if (condition == NULL)
442 len += strlen(" AND ");
443 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
445 len += strlen(condition);
446 strncat(buf, condition, sizeof(buf) - len - 1);
451 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
452 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
453 len += strlen(join_localized_info);
454 *bind_params = g_list_append(*bind_params, strdup(locale));
456 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
457 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
458 len += strlen(join_privilege_info);
460 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
462 *query = strdup(buf2);
464 return PMINFO_R_ERROR;
469 static void __free_packages(gpointer data)
471 pkgmgrinfo_basic_free_package((package_x *)data);
474 static int __bind_params(sqlite3_stmt *stmt, GList *params)
476 GList *tmp_list = NULL;
480 if (stmt == NULL || params == NULL)
481 return PMINFO_R_EINVAL;
485 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
486 if (ret != SQLITE_OK)
487 return PMINFO_R_ERROR;
488 tmp_list = tmp_list->next;
494 static int _pkginfo_get_packages(uid_t uid, const char *locale,
495 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
497 static const char query_raw[] =
498 "SELECT DISTINCT pi.package, pi.package_version, "
499 "pi.install_location, pi.package_removable, "
500 "pi.package_preload, pi.package_readonly, pi.package_update, "
501 "pi.package_appsetting, pi.package_system, pi.package_type, "
502 "pi.package_size, pi.installed_time, pi.installed_storage, "
503 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
504 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
505 "pi.package_api_version, pi.package_support_disable, "
506 "pi.package_tep_name, pi.package_zip_mount_file "
507 "FROM package_info as pi ";
508 int ret = PMINFO_R_ERROR;
511 char *constraints = NULL;
512 char query[MAX_QUERY_LEN] = { '\0' };
513 package_x *info = NULL;
514 GList *bind_params = NULL;
517 pkgmgrinfo_filter_x *tmp_filter = NULL;
519 dbpath = getUserPkgParserDBPathUID(uid);
521 return PMINFO_R_ERROR;
523 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
524 if (ret != SQLITE_OK) {
525 _LOGD("failed to open db: %d", ret);
526 return PMINFO_R_ERROR;
529 if (filter != NULL) {
532 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
533 if (ret != PMINFO_R_OK) {
534 _LOGE("Failed to create filter");
535 return PMINFO_R_ERROR;
539 /* add package_disable='false' clause by default */
540 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
542 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
543 if (ret != PMINFO_R_OK) {
544 LOGE("Failed to get WHERE clause");
549 snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraints);
551 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
553 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
554 if (ret != SQLITE_OK) {
555 LOGE("prepare failed: %s", sqlite3_errmsg(db));
556 ret = PMINFO_R_ERROR;
560 ret = __bind_params(stmt, bind_params);
561 if (ret != SQLITE_OK) {
562 LOGE("Failed to bind parameters");
566 while (sqlite3_step(stmt) == SQLITE_ROW) {
567 info = calloc(1, sizeof(package_x));
569 LOGE("out of memory");
570 sqlite3_finalize(stmt);
571 sqlite3_close_v2(db);
572 return PMINFO_R_ERROR;
575 _save_column_str(stmt, idx++, &info->package);
576 if (g_hash_table_contains(packages,
577 (gconstpointer)info->package)) {
582 _save_column_str(stmt, idx++, &info->version);
583 _save_column_str(stmt, idx++, &info->installlocation);
584 _save_column_str(stmt, idx++, &info->removable);
585 _save_column_str(stmt, idx++, &info->preload);
586 _save_column_str(stmt, idx++, &info->readonly);
587 _save_column_str(stmt, idx++, &info->update);
588 _save_column_str(stmt, idx++, &info->appsetting);
589 _save_column_str(stmt, idx++, &info->system);
590 _save_column_str(stmt, idx++, &info->type);
591 _save_column_str(stmt, idx++, &info->package_size);
592 _save_column_str(stmt, idx++, &info->installed_time);
593 _save_column_str(stmt, idx++, &info->installed_storage);
594 _save_column_str(stmt, idx++, &info->storeclient_id);
595 _save_column_str(stmt, idx++, &info->mainapp_id);
596 _save_column_str(stmt, idx++, &info->package_url);
597 _save_column_str(stmt, idx++, &info->root_path);
598 _save_column_str(stmt, idx++, &info->csc_path);
599 _save_column_str(stmt, idx++, &info->nodisplay_setting);
600 _save_column_str(stmt, idx++, &info->api_version);
601 _save_column_str(stmt, idx++, &info->support_disable);
602 _save_column_str(stmt, idx++, &info->tep_name);
603 _save_column_str(stmt, idx++, &info->zip_mount_file);
604 info->for_all_users =
605 strdup((uid != GLOBAL_USER) ? "false" : "true");
607 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
608 if (_pkginfo_get_author(db, info->package,
610 pkgmgrinfo_basic_free_package(info);
611 sqlite3_finalize(stmt);
612 sqlite3_close_v2(db);
613 return PMINFO_R_ERROR;
617 if (flag & PMINFO_PKGINFO_GET_LABEL) {
618 if (_pkginfo_get_label(db, info->package, locale,
620 pkgmgrinfo_basic_free_package(info);
621 sqlite3_finalize(stmt);
622 sqlite3_close_v2(db);
623 return PMINFO_R_ERROR;
627 if (flag & PMINFO_PKGINFO_GET_ICON) {
628 if (_pkginfo_get_icon(db, info->package, locale,
630 pkgmgrinfo_basic_free_package(info);
631 sqlite3_finalize(stmt);
632 sqlite3_close_v2(db);
633 return PMINFO_R_ERROR;
637 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
638 if (_pkginfo_get_description(db, info->package, locale,
639 &info->description)) {
640 pkgmgrinfo_basic_free_package(info);
641 sqlite3_finalize(stmt);
642 sqlite3_close_v2(db);
643 return PMINFO_R_ERROR;
647 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
648 if (_pkginfo_get_privilege(db, info->package,
649 &info->privileges)) {
650 pkgmgrinfo_basic_free_package(info);
651 sqlite3_finalize(stmt);
652 sqlite3_close_v2(db);
653 return PMINFO_R_ERROR;
657 g_hash_table_insert(packages, (gpointer)info->package,
667 if (ret != PMINFO_R_OK && info != NULL)
668 pkgmgrinfo_basic_free_package(info);
671 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
673 g_list_free_full(bind_params, free);
674 sqlite3_close_v2(db);
675 sqlite3_finalize(stmt);
680 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
681 pkgmgrinfo_filter_x *filter, int flag,
682 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
687 pkgmgr_pkginfo_x info;
692 locale = _get_system_locale();
694 return PMINFO_R_ERROR;
696 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
700 return PMINFO_R_ERROR;
703 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
704 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
705 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
708 if (ret != PMINFO_R_OK) {
709 g_hash_table_destroy(list);
711 return PMINFO_R_ERROR;
714 g_hash_table_iter_init(&iter, list);
715 while (g_hash_table_iter_next(&iter, NULL, &value)) {
716 pkg = (package_x *)value;
719 info.locale = locale;
720 if (pkg_list_cb(&info, user_data) < 0)
724 g_hash_table_destroy(list);
730 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
731 pkgmgrinfo_pkginfo_h *handle)
736 pkgmgrinfo_pkginfo_filter_h filter;
737 pkgmgr_pkginfo_x *info;
739 if (pkgid == NULL || handle == NULL) {
740 LOGE("invalid parameter");
741 return PMINFO_R_EINVAL;
744 locale = _get_system_locale();
746 return PMINFO_R_ERROR;
748 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
749 if (ret != PMINFO_R_OK) {
754 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
755 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
756 if (ret != PMINFO_R_OK) {
757 pkgmgrinfo_pkginfo_filter_destroy(filter);
759 return PMINFO_R_ERROR;
762 list = g_hash_table_new(g_str_hash, g_str_equal);
764 pkgmgrinfo_pkginfo_filter_destroy(filter);
766 return PMINFO_R_ERROR;
769 ret = _pkginfo_get_packages(uid, locale, filter,
770 PMINFO_PKGINFO_GET_ALL, list);
771 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
772 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
773 PMINFO_PKGINFO_GET_ALL, list);
775 pkgmgrinfo_pkginfo_filter_destroy(filter);
776 if (ret != PMINFO_R_OK) {
777 g_hash_table_destroy(list);
782 if (!g_hash_table_size(list)) {
783 _LOGI("pkginfo for [%s] is not existed for user [%d]",
785 g_hash_table_destroy(list);
787 return PMINFO_R_ENOENT;
790 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
792 _LOGE("out of memory");
793 g_hash_table_destroy(list);
795 return PMINFO_R_ERROR;
799 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
800 info->locale = locale;
802 /* just free list only */
803 g_hash_table_destroy(list);
810 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
811 pkgmgrinfo_pkginfo_h *handle)
813 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
816 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
817 int flag, void *user_data, uid_t uid)
819 if (pkg_list_cb == NULL) {
820 LOGE("invalid parameter");
821 return PMINFO_R_EINVAL;
824 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
825 pkg_list_cb, user_data);
828 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
829 int flag, void *user_data)
831 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
832 user_data, _getuid());
835 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
836 void *user_data, uid_t uid)
838 if (pkg_list_cb == NULL) {
839 LOGE("invalid parameter");
840 return PMINFO_R_EINVAL;
843 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
844 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
847 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
850 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
854 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
856 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
859 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
861 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
862 return PMINFO_R_ERROR;
864 *pkg_name = (char *)info->pkg_info->package;
869 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
871 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
873 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
874 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
876 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
877 return PMINFO_R_ERROR;
879 *pkgid = (char *)info->pkg_info->package;
884 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
886 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
888 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
889 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
891 if (info->pkg_info == NULL || info->pkg_info->type == NULL)
892 return PMINFO_R_ERROR;
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 || info->pkg_info->version == NULL)
907 return PMINFO_R_ERROR;
909 *version = (char *)info->pkg_info->version;
914 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
916 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
919 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
921 if (info->pkg_info == NULL || info->pkg_info->api_version == NULL)
922 return PMINFO_R_ERROR;
924 *api_version = (char *)info->pkg_info->api_version;
929 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
931 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
933 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
934 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
936 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
937 return PMINFO_R_ERROR;
939 if (strlen(info->pkg_info->tep_name) == 0)
940 return PMINFO_R_ERROR;
942 *tep_name = (char *)info->pkg_info->tep_name;
947 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
949 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
951 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
952 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
954 if (info->pkg_info == NULL)
955 return PMINFO_R_ERROR;
957 if (strlen(info->pkg_info->zip_mount_file) > 0)
958 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
963 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
966 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
968 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
969 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
971 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
972 return PMINFO_R_ERROR;
974 val = (char *)info->pkg_info->installlocation;
975 if (strcmp(val, "internal-only") == 0)
976 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
977 else if (strcmp(val, "prefer-external") == 0)
978 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
980 *location = PMINFO_INSTALL_LOCATION_AUTO;
985 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
987 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
989 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
990 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
992 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
993 return PMINFO_R_ERROR;
995 *size = atoi((char *)info->pkg_info->package_size);
1000 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
1003 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1004 long long rw_size = 0;
1005 long long ro_size = 0;
1006 long long tmp_size = 0;
1007 long long total_size = 0;
1008 struct stat fileinfo;
1011 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1012 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1014 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1016 return PMINFO_R_ERROR;
1019 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
1020 if (lstat(device_path, &fileinfo) == 0) {
1021 if (!S_ISLNK(fileinfo.st_mode)) {
1022 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1024 rw_size += tmp_size;
1028 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
1029 if (lstat(device_path, &fileinfo) == 0) {
1030 if (!S_ISLNK(fileinfo.st_mode)) {
1031 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1033 rw_size += tmp_size;
1037 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
1038 if (lstat(device_path, &fileinfo) == 0) {
1039 if (!S_ISLNK(fileinfo.st_mode)) {
1040 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1042 rw_size += tmp_size;
1046 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1047 if (lstat(device_path, &fileinfo) == 0) {
1048 if (!S_ISLNK(fileinfo.st_mode)) {
1049 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1051 rw_size += tmp_size;
1055 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
1056 if (lstat(device_path, &fileinfo) == 0) {
1057 if (!S_ISLNK(fileinfo.st_mode)) {
1058 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1060 rw_size += tmp_size;
1064 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
1065 if (lstat(device_path, &fileinfo) == 0) {
1066 if (!S_ISLNK(fileinfo.st_mode)) {
1067 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1069 rw_size += tmp_size;
1074 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
1075 if (lstat(device_path, &fileinfo) == 0) {
1076 if (!S_ISLNK(fileinfo.st_mode)) {
1077 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1079 ro_size += tmp_size;
1083 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
1084 if (lstat(device_path, &fileinfo) == 0) {
1085 if (!S_ISLNK(fileinfo.st_mode)) {
1086 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1088 ro_size += tmp_size;
1092 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
1093 if (lstat(device_path, &fileinfo) == 0) {
1094 if (!S_ISLNK(fileinfo.st_mode)) {
1095 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1097 ro_size += tmp_size;
1101 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
1102 if (lstat(device_path, &fileinfo) == 0) {
1103 if (!S_ISLNK(fileinfo.st_mode)) {
1104 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1106 ro_size += tmp_size;
1110 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
1111 if (lstat(device_path, &fileinfo) == 0) {
1112 if (!S_ISLNK(fileinfo.st_mode)) {
1113 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1115 ro_size += tmp_size;
1119 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
1120 if (lstat(device_path, &fileinfo) == 0) {
1121 if (!S_ISLNK(fileinfo.st_mode)) {
1122 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1124 ro_size += tmp_size;
1129 total_size = rw_size + ro_size;
1130 *size = (int)total_size;
1135 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1138 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1139 long long total_size = 0;
1141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1142 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1144 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1145 return PMINFO_R_ERROR;
1147 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1148 if (access(device_path, R_OK) == 0)
1149 total_size = _pkgmgr_calculate_dir_size(device_path);
1151 return PMINFO_R_ERROR;
1153 *size = (int)total_size;
1158 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1163 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1165 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1166 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1168 locale = info->locale;
1169 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1171 if (info->pkg_info == NULL)
1172 return PMINFO_R_ERROR;
1174 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1175 ptr = (icon_x *)tmp->data;
1176 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1177 !strcasecmp(ptr->text, "(null)") ||
1178 strcmp(ptr->lang, locale))
1180 *icon = (char *)ptr->text;
1184 locale = DEFAULT_LOCALE;
1185 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1186 ptr = (icon_x *)tmp->data;
1187 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1188 strcmp(ptr->lang, locale))
1190 *icon = (char *)ptr->text;
1194 return PMINFO_R_ERROR;
1197 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1202 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1205 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1207 locale = info->locale;
1208 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1210 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1211 ptr = (label_x *)tmp->data;
1212 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1213 strcmp(ptr->lang, locale))
1215 *label = (char *)ptr->text;
1219 locale = DEFAULT_LOCALE;
1220 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1221 ptr = (label_x *)tmp->data;
1222 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1223 strcmp(ptr->lang, locale))
1225 *label = (char *)ptr->text;
1229 return PMINFO_R_ERROR;
1232 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1237 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1240 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1242 locale = info->locale;
1243 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1245 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1246 ptr = (description_x *)tmp->data;
1247 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1248 strcmp(ptr->lang, locale))
1250 *description = (char *)ptr->text;
1254 locale = DEFAULT_LOCALE;
1255 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1256 ptr = (description_x *)tmp->data;
1257 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1258 strcmp(ptr->lang, locale))
1260 *description = (char *)ptr->text;
1264 return PMINFO_R_ERROR;
1267 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1269 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1273 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1275 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1276 return PMINFO_R_ERROR;
1278 author = (author_x *)info->pkg_info->author->data;
1279 if (author == NULL || author->text == NULL)
1280 return PMINFO_R_ERROR;
1282 *author_name = (char *)author->text;
1287 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1289 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1292 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1293 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1295 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1296 return PMINFO_R_ERROR;
1298 author = (author_x *)info->pkg_info->author->data;
1299 if (author == NULL || author->email == NULL)
1300 return PMINFO_R_ERROR;
1302 *author_email = (char *)author->email;
1307 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1309 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1312 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1313 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1315 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1316 return PMINFO_R_ERROR;
1318 author = (author_x *)info->pkg_info->author->data;
1319 if (author == NULL || author->href == NULL)
1320 return PMINFO_R_ERROR;
1322 *author_href = (char *)author->href;
1327 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1329 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1331 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1332 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1334 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1335 return PMINFO_R_ERROR;
1337 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1338 *storage = PMINFO_INTERNAL_STORAGE;
1339 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1340 *storage = PMINFO_EXTERNAL_STORAGE;
1342 return PMINFO_R_ERROR;
1347 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1349 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1351 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1352 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1354 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1355 return PMINFO_R_ERROR;
1357 *installed_time = atoi(info->pkg_info->installed_time);
1362 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1364 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1366 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1367 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1369 if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
1370 return PMINFO_R_ERROR;
1372 *storeclientid = (char *)info->pkg_info->storeclient_id;
1377 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
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(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1384 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1385 return PMINFO_R_ERROR;
1387 *mainappid = (char *)info->pkg_info->mainapp_id;
1392 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
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(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1399 if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
1400 return PMINFO_R_ERROR;
1402 *url = (char *)info->pkg_info->package_url;
1407 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1409 const char *val = NULL;
1410 const xmlChar *node;
1411 xmlTextReaderPtr reader;
1412 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1413 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1416 reader = xmlReaderForFile(manifest, NULL, 0);
1419 if (__child_element(reader, -1)) {
1420 node = xmlTextReaderConstName(reader);
1422 _LOGE("xmlTextReaderConstName value is NULL\n");
1423 xmlFreeTextReader(reader);
1425 return PMINFO_R_ERROR;
1428 if (!strcmp(ASC_CHAR(node), "manifest")) {
1429 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1430 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1436 _LOGE("package size is not specified\n");
1437 xmlFreeTextReader(reader);
1439 return PMINFO_R_ERROR;
1442 _LOGE("Unable to create xml reader\n");
1443 xmlFreeTextReader(reader);
1445 return PMINFO_R_ERROR;
1449 _LOGE("xmlReaderForFile value is NULL\n");
1451 return PMINFO_R_ERROR;
1454 xmlFreeTextReader(reader);
1460 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1462 const char *val = NULL;
1463 const xmlChar *node;
1464 xmlTextReaderPtr reader;
1465 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1466 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1469 reader = xmlReaderForFile(manifest, NULL, 0);
1472 if ( __child_element(reader, -1)) {
1473 node = xmlTextReaderConstName(reader);
1475 _LOGE("xmlTextReaderConstName value is NULL\n");
1476 xmlFreeTextReader(reader);
1478 return PMINFO_R_ERROR;
1481 if (!strcmp(ASC_CHAR(node), "manifest")) {
1482 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1483 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1486 if (strcmp(val, "internal-only") == 0)
1487 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1488 else if (strcmp(val, "prefer-external") == 0)
1489 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1491 *location = PMINFO_INSTALL_LOCATION_AUTO;
1494 _LOGE("Unable to create xml reader\n");
1495 xmlFreeTextReader(reader);
1497 return PMINFO_R_ERROR;
1501 _LOGE("xmlReaderForFile value is NULL\n");
1503 return PMINFO_R_ERROR;
1506 xmlFreeTextReader(reader);
1513 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1515 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1518 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1520 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1521 return PMINFO_R_ERROR;
1523 *path = (char *)info->pkg_info->root_path;
1528 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1530 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1533 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1535 if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
1536 return PMINFO_R_ERROR;
1538 *path = (char *)info->pkg_info->csc_path;
1544 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1547 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1549 #if 0 //smack issue occured, check later
1551 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1553 _LOGD("invalid func parameters\n");
1554 return PMINFO_R_ERROR;
1556 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1559 char app_mmc_path[FILENAME_MAX] = { 0, };
1560 char app_dir_path[FILENAME_MAX] = { 0, };
1561 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1562 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1563 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1564 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1566 /*check whether application is in external memory or not */
1567 fp = fopen(app_mmc_path, "r");
1569 _LOGD(" app path in external memory not accesible\n");
1574 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1578 /*check whether application is in internal or not */
1579 fp = fopen(app_dir_path, "r");
1581 _LOGD(" app path in internal memory not accesible\n");
1583 return PMINFO_R_ERROR;
1586 /*check whether the application is installed in SD card
1587 but SD card is not present*/
1588 fp = fopen(app_mmc_internal_path, "r");
1591 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1596 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1601 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1608 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1610 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1612 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1613 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1615 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1616 return PMINFO_R_ERROR;
1618 *removable = _get_bool_value(info->pkg_info->removable);
1623 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1626 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1628 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1629 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1631 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1632 return PMINFO_R_ERROR;
1634 val = (char *)info->pkg_info->installlocation;
1635 if (strcmp(val, "internal-only") == 0)
1637 else if (strcmp(val, "prefer-external") == 0)
1645 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1647 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1649 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1650 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1652 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1653 return PMINFO_R_ERROR;
1655 *preload = _get_bool_value(info->pkg_info->preload);
1660 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
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(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1667 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1668 return PMINFO_R_ERROR;
1670 *system = _get_bool_value(info->pkg_info->system);
1675 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1677 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1680 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1682 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1683 return PMINFO_R_ERROR;
1685 *readonly = _get_bool_value(info->pkg_info->readonly);
1690 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1692 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1694 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1695 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1697 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1698 return PMINFO_R_ERROR;
1700 *update = _get_bool_value(info->pkg_info->update);
1705 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1707 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1709 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1710 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1712 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1713 return PMINFO_R_ERROR;
1715 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1720 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1722 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1724 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1725 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1727 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1728 return PMINFO_R_ERROR;
1730 *global = _get_bool_value(info->pkg_info->for_all_users);
1735 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1737 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1740 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1742 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1746 __cleanup_pkginfo(info);
1751 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1753 pkgmgrinfo_filter_x *filter;
1755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1757 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1758 if (filter == NULL) {
1759 _LOGE("Out of Memory!!!");
1760 return PMINFO_R_ERROR;
1768 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1770 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1772 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1775 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1776 g_slist_free(filter->list);
1784 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1785 const char *property, const int value)
1787 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1791 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1792 pkgmgrinfo_node_x *node;
1794 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1795 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1797 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1798 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1799 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1800 _LOGE("Invalid Integer Property\n");
1801 return PMINFO_R_EINVAL;
1803 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1805 _LOGE("Out of Memory!!!\n");
1806 return PMINFO_R_ERROR;
1808 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1809 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1811 _LOGE("Out of Memory\n");
1813 return PMINFO_R_ERROR;
1817 /*If API is called multiple times for same property, we should override the previous values.
1818 Last value set will be used for filtering.*/
1819 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1821 filter->list = g_slist_delete_link(filter->list, link);
1822 filter->list = g_slist_append(filter->list, (gpointer)node);
1827 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1828 const char *property, const bool value)
1833 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1834 pkgmgrinfo_node_x *node;
1836 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1837 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1839 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1840 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1841 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1842 _LOGE("Invalid Boolean Property\n");
1843 return PMINFO_R_EINVAL;
1845 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1847 _LOGE("Out of Memory!!!\n");
1848 return PMINFO_R_ERROR;
1851 val = strndup("true", 4);
1853 val = strndup("false", 5);
1855 _LOGE("Out of Memory\n");
1857 return PMINFO_R_ERROR;
1861 /*If API is called multiple times for same property, we should override the previous values.
1862 Last value set will be used for filtering.*/
1863 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1865 filter->list = g_slist_delete_link(filter->list, link);
1866 filter->list = g_slist_append(filter->list, (gpointer)node);
1871 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1872 const char *property, const char *value)
1877 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1878 pkgmgrinfo_node_x *node;
1880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1881 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1882 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1884 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1885 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1886 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1887 _LOGE("Invalid String Property\n");
1888 return PMINFO_R_EINVAL;
1890 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1892 _LOGE("Out of Memory!!!\n");
1893 return PMINFO_R_ERROR;
1895 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1896 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1897 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1898 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1899 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1900 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1901 else if (strcmp(value, "installed_internal") == 0)
1902 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1903 else if (strcmp(value, "installed_external") == 0)
1904 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1906 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1908 _LOGE("Out of Memory\n");
1910 return PMINFO_R_ERROR;
1914 /*If API is called multiple times for same property, we should override the previous values.
1915 Last value set will be used for filtering.*/
1916 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1918 filter->list = g_slist_delete_link(filter->list, link);
1919 filter->list = g_slist_append(filter->list, (gpointer)node);
1924 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1928 GHashTable *list = NULL;
1930 if (handle == NULL || count == NULL) {
1931 _LOGE("invalid parameter");
1932 return PMINFO_R_EINVAL;
1935 locale = _get_system_locale();
1937 return PMINFO_R_ERROR;
1939 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1943 return PMINFO_R_ERROR;
1946 ret = _pkginfo_get_packages(uid, locale,
1947 (pkgmgrinfo_filter_x *)handle, 0, list);
1948 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1949 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1952 if (ret != PMINFO_R_OK) {
1953 g_hash_table_destroy(list);
1955 return PMINFO_R_ERROR;
1958 *count = g_hash_table_size(list);
1960 g_hash_table_destroy(list);
1966 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1968 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1971 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1972 pkgmgrinfo_pkginfo_filter_h handle,
1973 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1975 if (handle == NULL || pkg_cb == NULL) {
1976 LOGE("invalid parameter");
1977 return PMINFO_R_EINVAL;
1980 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1981 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1984 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1985 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1987 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1990 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1991 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1993 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1994 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1996 const char *privilege;
1998 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2000 if (info->pkg_info == NULL)
2001 return PMINFO_R_ERROR;
2003 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2004 privilege = (const char *)tmp->data;
2005 if (privilege == NULL)
2007 ret = privilege_func(privilege, user_data);