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 (info->pkg_info->zip_mount_file &&
958 strlen(info->pkg_info->zip_mount_file) > 0)
959 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
964 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
967 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
970 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
972 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
973 return PMINFO_R_ERROR;
975 val = (char *)info->pkg_info->installlocation;
976 if (strcmp(val, "internal-only") == 0)
977 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
978 else if (strcmp(val, "prefer-external") == 0)
979 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
981 *location = PMINFO_INSTALL_LOCATION_AUTO;
986 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
988 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
991 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
993 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
994 return PMINFO_R_ERROR;
996 *size = atoi((char *)info->pkg_info->package_size);
1001 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
1004 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1005 long long rw_size = 0;
1006 long long ro_size = 0;
1007 long long tmp_size = 0;
1008 long long total_size = 0;
1009 struct stat fileinfo;
1012 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1013 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1015 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1017 return PMINFO_R_ERROR;
1020 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
1021 if (lstat(device_path, &fileinfo) == 0) {
1022 if (!S_ISLNK(fileinfo.st_mode)) {
1023 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1025 rw_size += tmp_size;
1029 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
1030 if (lstat(device_path, &fileinfo) == 0) {
1031 if (!S_ISLNK(fileinfo.st_mode)) {
1032 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1034 rw_size += tmp_size;
1038 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
1039 if (lstat(device_path, &fileinfo) == 0) {
1040 if (!S_ISLNK(fileinfo.st_mode)) {
1041 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1043 rw_size += tmp_size;
1047 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1048 if (lstat(device_path, &fileinfo) == 0) {
1049 if (!S_ISLNK(fileinfo.st_mode)) {
1050 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1052 rw_size += tmp_size;
1056 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
1057 if (lstat(device_path, &fileinfo) == 0) {
1058 if (!S_ISLNK(fileinfo.st_mode)) {
1059 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1061 rw_size += tmp_size;
1065 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
1066 if (lstat(device_path, &fileinfo) == 0) {
1067 if (!S_ISLNK(fileinfo.st_mode)) {
1068 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1070 rw_size += tmp_size;
1075 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
1076 if (lstat(device_path, &fileinfo) == 0) {
1077 if (!S_ISLNK(fileinfo.st_mode)) {
1078 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1080 ro_size += tmp_size;
1084 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
1085 if (lstat(device_path, &fileinfo) == 0) {
1086 if (!S_ISLNK(fileinfo.st_mode)) {
1087 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1089 ro_size += tmp_size;
1093 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
1094 if (lstat(device_path, &fileinfo) == 0) {
1095 if (!S_ISLNK(fileinfo.st_mode)) {
1096 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1098 ro_size += tmp_size;
1102 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
1103 if (lstat(device_path, &fileinfo) == 0) {
1104 if (!S_ISLNK(fileinfo.st_mode)) {
1105 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1107 ro_size += tmp_size;
1111 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
1112 if (lstat(device_path, &fileinfo) == 0) {
1113 if (!S_ISLNK(fileinfo.st_mode)) {
1114 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1116 ro_size += tmp_size;
1120 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
1121 if (lstat(device_path, &fileinfo) == 0) {
1122 if (!S_ISLNK(fileinfo.st_mode)) {
1123 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1125 ro_size += tmp_size;
1130 total_size = rw_size + ro_size;
1131 *size = (int)total_size;
1136 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1139 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1140 long long total_size = 0;
1142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1143 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1145 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1146 return PMINFO_R_ERROR;
1148 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1149 if (access(device_path, R_OK) == 0)
1150 total_size = _pkgmgr_calculate_dir_size(device_path);
1152 return PMINFO_R_ERROR;
1154 *size = (int)total_size;
1159 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1164 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1167 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1169 locale = info->locale;
1170 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1172 if (info->pkg_info == NULL)
1173 return PMINFO_R_ERROR;
1175 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1176 ptr = (icon_x *)tmp->data;
1177 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1178 !strcasecmp(ptr->text, "(null)") ||
1179 strcmp(ptr->lang, locale))
1181 *icon = (char *)ptr->text;
1185 locale = DEFAULT_LOCALE;
1186 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1187 ptr = (icon_x *)tmp->data;
1188 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1189 strcmp(ptr->lang, locale))
1191 *icon = (char *)ptr->text;
1195 return PMINFO_R_ERROR;
1198 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1203 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1206 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1208 locale = info->locale;
1209 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1211 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1212 ptr = (label_x *)tmp->data;
1213 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1214 strcmp(ptr->lang, locale))
1216 *label = (char *)ptr->text;
1220 locale = DEFAULT_LOCALE;
1221 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1222 ptr = (label_x *)tmp->data;
1223 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1224 strcmp(ptr->lang, locale))
1226 *label = (char *)ptr->text;
1230 return PMINFO_R_ERROR;
1233 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1238 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1240 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1241 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1243 locale = info->locale;
1244 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1246 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1247 ptr = (description_x *)tmp->data;
1248 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1249 strcmp(ptr->lang, locale))
1251 *description = (char *)ptr->text;
1255 locale = DEFAULT_LOCALE;
1256 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1257 ptr = (description_x *)tmp->data;
1258 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1259 strcmp(ptr->lang, locale))
1261 *description = (char *)ptr->text;
1265 return PMINFO_R_ERROR;
1268 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1270 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1274 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1276 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1277 return PMINFO_R_ERROR;
1279 author = (author_x *)info->pkg_info->author->data;
1280 if (author == NULL || author->text == NULL)
1281 return PMINFO_R_ERROR;
1283 *author_name = (char *)author->text;
1288 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1290 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1293 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1294 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1296 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1297 return PMINFO_R_ERROR;
1299 author = (author_x *)info->pkg_info->author->data;
1300 if (author == NULL || author->email == NULL)
1301 return PMINFO_R_ERROR;
1303 *author_email = (char *)author->email;
1308 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1310 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1314 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1316 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1317 return PMINFO_R_ERROR;
1319 author = (author_x *)info->pkg_info->author->data;
1320 if (author == NULL || author->href == NULL)
1321 return PMINFO_R_ERROR;
1323 *author_href = (char *)author->href;
1328 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1330 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1333 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1335 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1336 return PMINFO_R_ERROR;
1338 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1339 *storage = PMINFO_INTERNAL_STORAGE;
1340 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1341 *storage = PMINFO_EXTERNAL_STORAGE;
1343 return PMINFO_R_ERROR;
1348 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1350 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1352 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1353 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1355 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1356 return PMINFO_R_ERROR;
1358 *installed_time = atoi(info->pkg_info->installed_time);
1363 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1367 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1368 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1370 if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
1371 return PMINFO_R_ERROR;
1373 *storeclientid = (char *)info->pkg_info->storeclient_id;
1378 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1380 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1383 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1385 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1386 return PMINFO_R_ERROR;
1388 *mainappid = (char *)info->pkg_info->mainapp_id;
1393 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1395 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1398 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1400 if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
1401 return PMINFO_R_ERROR;
1403 *url = (char *)info->pkg_info->package_url;
1408 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1410 const char *val = NULL;
1411 const xmlChar *node;
1412 xmlTextReaderPtr reader;
1413 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1414 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1417 reader = xmlReaderForFile(manifest, NULL, 0);
1420 if (__child_element(reader, -1)) {
1421 node = xmlTextReaderConstName(reader);
1423 _LOGE("xmlTextReaderConstName value is NULL\n");
1424 xmlFreeTextReader(reader);
1426 return PMINFO_R_ERROR;
1429 if (!strcmp(ASC_CHAR(node), "manifest")) {
1430 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1431 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1437 _LOGE("package size is not specified\n");
1438 xmlFreeTextReader(reader);
1440 return PMINFO_R_ERROR;
1443 _LOGE("Unable to create xml reader\n");
1444 xmlFreeTextReader(reader);
1446 return PMINFO_R_ERROR;
1450 _LOGE("xmlReaderForFile value is NULL\n");
1452 return PMINFO_R_ERROR;
1455 xmlFreeTextReader(reader);
1461 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1463 const char *val = NULL;
1464 const xmlChar *node;
1465 xmlTextReaderPtr reader;
1466 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1467 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1470 reader = xmlReaderForFile(manifest, NULL, 0);
1473 if ( __child_element(reader, -1)) {
1474 node = xmlTextReaderConstName(reader);
1476 _LOGE("xmlTextReaderConstName value is NULL\n");
1477 xmlFreeTextReader(reader);
1479 return PMINFO_R_ERROR;
1482 if (!strcmp(ASC_CHAR(node), "manifest")) {
1483 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1484 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1487 if (strcmp(val, "internal-only") == 0)
1488 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1489 else if (strcmp(val, "prefer-external") == 0)
1490 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1492 *location = PMINFO_INSTALL_LOCATION_AUTO;
1495 _LOGE("Unable to create xml reader\n");
1496 xmlFreeTextReader(reader);
1498 return PMINFO_R_ERROR;
1502 _LOGE("xmlReaderForFile value is NULL\n");
1504 return PMINFO_R_ERROR;
1507 xmlFreeTextReader(reader);
1514 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1516 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1519 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1521 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1522 return PMINFO_R_ERROR;
1524 *path = (char *)info->pkg_info->root_path;
1529 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1531 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1534 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1536 if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
1537 return PMINFO_R_ERROR;
1539 *path = (char *)info->pkg_info->csc_path;
1545 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1547 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1548 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1550 #if 0 //smack issue occured, check later
1552 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1554 _LOGD("invalid func parameters\n");
1555 return PMINFO_R_ERROR;
1557 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1560 char app_mmc_path[FILENAME_MAX] = { 0, };
1561 char app_dir_path[FILENAME_MAX] = { 0, };
1562 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1563 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1564 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1565 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1567 /*check whether application is in external memory or not */
1568 fp = fopen(app_mmc_path, "r");
1570 _LOGD(" app path in external memory not accesible\n");
1575 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1579 /*check whether application is in internal or not */
1580 fp = fopen(app_dir_path, "r");
1582 _LOGD(" app path in internal memory not accesible\n");
1584 return PMINFO_R_ERROR;
1587 /*check whether the application is installed in SD card
1588 but SD card is not present*/
1589 fp = fopen(app_mmc_internal_path, "r");
1592 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1597 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1602 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1609 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1611 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1613 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1614 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1616 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1617 return PMINFO_R_ERROR;
1619 *removable = _get_bool_value(info->pkg_info->removable);
1624 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1627 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1630 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1632 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1633 return PMINFO_R_ERROR;
1635 val = (char *)info->pkg_info->installlocation;
1636 if (strcmp(val, "internal-only") == 0)
1638 else if (strcmp(val, "prefer-external") == 0)
1646 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1650 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1651 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1653 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1654 return PMINFO_R_ERROR;
1656 *preload = _get_bool_value(info->pkg_info->preload);
1661 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1663 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1665 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1666 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1668 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1669 return PMINFO_R_ERROR;
1671 *system = _get_bool_value(info->pkg_info->system);
1676 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1678 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1681 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1683 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1684 return PMINFO_R_ERROR;
1686 *readonly = _get_bool_value(info->pkg_info->readonly);
1691 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1693 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1696 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1698 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1699 return PMINFO_R_ERROR;
1701 *update = _get_bool_value(info->pkg_info->update);
1706 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1708 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1710 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1711 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1713 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1714 return PMINFO_R_ERROR;
1716 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1721 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1723 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1726 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1728 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1729 return PMINFO_R_ERROR;
1731 *global = _get_bool_value(info->pkg_info->for_all_users);
1736 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1738 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1741 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1743 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1747 __cleanup_pkginfo(info);
1752 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1754 pkgmgrinfo_filter_x *filter;
1756 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1758 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1759 if (filter == NULL) {
1760 _LOGE("Out of Memory!!!");
1761 return PMINFO_R_ERROR;
1769 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1771 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1776 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1777 g_slist_free(filter->list);
1785 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1786 const char *property, const int value)
1788 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1792 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1793 pkgmgrinfo_node_x *node;
1795 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1796 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1798 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1799 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1800 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1801 _LOGE("Invalid Integer Property\n");
1802 return PMINFO_R_EINVAL;
1804 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1806 _LOGE("Out of Memory!!!\n");
1807 return PMINFO_R_ERROR;
1809 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1810 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1812 _LOGE("Out of Memory\n");
1814 return PMINFO_R_ERROR;
1818 /*If API is called multiple times for same property, we should override the previous values.
1819 Last value set will be used for filtering.*/
1820 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1822 filter->list = g_slist_delete_link(filter->list, link);
1823 filter->list = g_slist_append(filter->list, (gpointer)node);
1828 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1829 const char *property, const bool value)
1834 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1835 pkgmgrinfo_node_x *node;
1837 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1838 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1840 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1841 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1842 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1843 _LOGE("Invalid Boolean Property\n");
1844 return PMINFO_R_EINVAL;
1846 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1848 _LOGE("Out of Memory!!!\n");
1849 return PMINFO_R_ERROR;
1852 val = strndup("true", 4);
1854 val = strndup("false", 5);
1856 _LOGE("Out of Memory\n");
1858 return PMINFO_R_ERROR;
1862 /*If API is called multiple times for same property, we should override the previous values.
1863 Last value set will be used for filtering.*/
1864 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1866 filter->list = g_slist_delete_link(filter->list, link);
1867 filter->list = g_slist_append(filter->list, (gpointer)node);
1872 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1873 const char *property, const char *value)
1878 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1879 pkgmgrinfo_node_x *node;
1881 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1882 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1883 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1885 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1886 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1887 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1888 _LOGE("Invalid String Property\n");
1889 return PMINFO_R_EINVAL;
1891 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1893 _LOGE("Out of Memory!!!\n");
1894 return PMINFO_R_ERROR;
1896 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1897 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1898 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1899 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1900 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1901 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1902 else if (strcmp(value, "installed_internal") == 0)
1903 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1904 else if (strcmp(value, "installed_external") == 0)
1905 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1907 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1909 _LOGE("Out of Memory\n");
1911 return PMINFO_R_ERROR;
1915 /*If API is called multiple times for same property, we should override the previous values.
1916 Last value set will be used for filtering.*/
1917 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1919 filter->list = g_slist_delete_link(filter->list, link);
1920 filter->list = g_slist_append(filter->list, (gpointer)node);
1925 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1929 GHashTable *list = NULL;
1931 if (handle == NULL || count == NULL) {
1932 _LOGE("invalid parameter");
1933 return PMINFO_R_EINVAL;
1936 locale = _get_system_locale();
1938 return PMINFO_R_ERROR;
1940 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1944 return PMINFO_R_ERROR;
1947 ret = _pkginfo_get_packages(uid, locale,
1948 (pkgmgrinfo_filter_x *)handle, 0, list);
1949 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1950 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1953 if (ret != PMINFO_R_OK) {
1954 g_hash_table_destroy(list);
1956 return PMINFO_R_ERROR;
1959 *count = g_hash_table_size(list);
1961 g_hash_table_destroy(list);
1967 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1969 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1972 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1973 pkgmgrinfo_pkginfo_filter_h handle,
1974 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1976 if (handle == NULL || pkg_cb == NULL) {
1977 LOGE("invalid parameter");
1978 return PMINFO_R_EINVAL;
1981 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1982 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1985 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1986 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1988 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1991 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1992 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1994 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1995 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1997 const char *privilege;
1999 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2001 if (info->pkg_info == NULL)
2002 return PMINFO_R_ERROR;
2004 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2005 privilege = (const char *)tmp->data;
2006 if (privilege == NULL)
2008 ret = privilege_func(privilege, user_data);