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 char *_get_filtered_query(const char *query_raw,
50 pkgmgrinfo_filter_x *filter);
52 static bool _get_bool_value(const char *str)
56 else if (!strcasecmp(str, "true"))
62 static gint __compare_func(gconstpointer data1, gconstpointer data2)
64 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
65 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
66 if (node1->prop == node2->prop)
68 else if (node1->prop > node2->prop)
74 static void __destroy_each_node(gpointer data, gpointer user_data)
77 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
90 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
94 free((void *)data->locale);
98 pkgmgrinfo_basic_free_package(data->pkg_info);
104 static int __child_element(xmlTextReaderPtr reader, int depth)
106 int ret = xmlTextReaderRead(reader);
107 int cur = xmlTextReaderDepth(reader);
110 switch (xmlTextReaderNodeType(reader)) {
111 case XML_READER_TYPE_ELEMENT:
112 if (cur == depth + 1)
115 case XML_READER_TYPE_TEXT:
116 /*text is handled by each function separately*/
117 if (cur == depth + 1)
120 case XML_READER_TYPE_END_ELEMENT:
129 ret = xmlTextReaderRead(reader);
130 cur = xmlTextReaderDepth(reader);
135 long long _pkgmgr_calculate_dir_size(char *dirname)
139 int q = 0; /*quotient*/
140 int r = 0; /*remainder*/
142 struct dirent ep, *result;
143 struct stat fileinfo;
144 char abs_filename[FILENAME_MAX] = { 0, };
145 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
147 dp = opendir(dirname);
149 _LOGE("Couldn't open the directory\n");
153 for (ret = readdir_r(dp, &ep, &result);
154 ret == 0 && result != NULL;
155 ret = readdir_r(dp, &ep, &result)) {
156 if (!strcmp(ep.d_name, ".") ||
157 !strcmp(ep.d_name, "..")) {
160 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
162 if (lstat(abs_filename, &fileinfo) < 0)
163 perror(abs_filename);
165 if (S_ISDIR(fileinfo.st_mode)) {
166 total += fileinfo.st_size;
167 if (strcmp(ep.d_name, ".")
168 && strcmp(ep.d_name, "..")) {
169 ret = _pkgmgr_calculate_dir_size
173 } else if (S_ISLNK(fileinfo.st_mode)) {
176 /*It is a file. Calculate the actual
177 size occupied (in terms of 4096 blocks)*/
178 q = (fileinfo.st_size / BLOCK_SIZE);
179 r = (fileinfo.st_size % BLOCK_SIZE);
183 total += q * BLOCK_SIZE;
192 static int _pkginfo_get_author(sqlite3 *db, const char *pkgid,
195 static const char query_raw[] =
196 "SELECT author_name, author_email, author_href "
197 "FROM package_info WHERE package=%Q";
204 query = sqlite3_mprintf(query_raw, pkgid);
206 LOGE("out of memory");
207 return PMINFO_R_ERROR;
210 ret = sqlite3_prepare_v2(db, query, strlen(query),
213 if (ret != SQLITE_OK) {
214 LOGE("prepare failed: %s", sqlite3_errmsg(db));
215 return PMINFO_R_ERROR;
218 if (sqlite3_step(stmt) == SQLITE_ERROR) {
219 LOGE("step error: %s", sqlite3_errmsg(db));
220 sqlite3_finalize(stmt);
221 return PMINFO_R_ERROR;
224 /* one author per one package */
225 info = calloc(1, sizeof(author_x));
227 LOGE("out of memory");
228 sqlite3_finalize(stmt);
229 return PMINFO_R_ERROR;
232 _save_column_str(stmt, idx++, &info->text);
233 _save_column_str(stmt, idx++, &info->email);
234 _save_column_str(stmt, idx++, &info->href);
237 *author = g_list_append(*author, info);
239 sqlite3_finalize(stmt);
244 static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
245 const char *locale, GList **label)
247 static const char query_raw[] =
248 "SELECT package_label, package_locale "
249 "FROM package_localized_info "
250 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
257 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
259 LOGE("out of memory");
260 return PMINFO_R_ERROR;
263 ret = sqlite3_prepare_v2(db, query, strlen(query),
266 if (ret != SQLITE_OK) {
267 LOGE("prepare failed: %s", sqlite3_errmsg(db));
268 return PMINFO_R_ERROR;
271 while (sqlite3_step(stmt) == SQLITE_ROW) {
272 info = calloc(1, sizeof(label_x));
274 LOGE("out of memory");
275 sqlite3_finalize(stmt);
276 return PMINFO_R_ERROR;
279 _save_column_str(stmt, idx++, &info->text);
280 _save_column_str(stmt, idx++, &info->lang);
281 *label = g_list_append(*label, info);
284 sqlite3_finalize(stmt);
289 static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
292 static const char query_raw[] =
293 "SELECT package_icon, package_locale "
294 "FROM package_localized_info "
295 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
302 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
304 LOGE("out of memory");
305 return PMINFO_R_ERROR;
308 ret = sqlite3_prepare_v2(db, query, strlen(query),
311 if (ret != SQLITE_OK) {
312 LOGE("prepare failed: %s", sqlite3_errmsg(db));
313 return PMINFO_R_ERROR;
316 while (sqlite3_step(stmt) == SQLITE_ROW) {
317 info = calloc(1, sizeof(icon_x));
319 LOGE("out of memory");
320 sqlite3_finalize(stmt);
321 return PMINFO_R_ERROR;
324 _save_column_str(stmt, idx++, &info->text);
325 _save_column_str(stmt, idx++, &info->lang);
326 *icon = g_list_append(*icon, info);
329 sqlite3_finalize(stmt);
334 static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
335 const char *locale, GList **description)
337 static const char query_raw[] =
338 "SELECT package_description, package_locale "
339 "FROM package_localized_info "
340 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
347 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
349 LOGE("out of memory");
350 return PMINFO_R_ERROR;
353 ret = sqlite3_prepare_v2(db, query, strlen(query),
356 if (ret != SQLITE_OK) {
357 LOGE("prepare failed: %s", sqlite3_errmsg(db));
358 return PMINFO_R_ERROR;
361 while (sqlite3_step(stmt) == SQLITE_ROW) {
362 info = calloc(1, sizeof(description_x));
364 LOGE("out of memory");
365 sqlite3_finalize(stmt);
366 return PMINFO_R_ERROR;
369 _save_column_str(stmt, idx++, &info->text);
370 _save_column_str(stmt, idx++, &info->lang);
371 *description = g_list_append(*description, info);
374 sqlite3_finalize(stmt);
379 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
382 static const char query_raw[] =
383 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
389 query = sqlite3_mprintf(query_raw, pkgid);
391 LOGE("out of memory");
392 return PMINFO_R_ERROR;
395 ret = sqlite3_prepare_v2(db, query, strlen(query),
398 if (ret != SQLITE_OK) {
399 LOGE("prepare failed: %s", sqlite3_errmsg(db));
400 return PMINFO_R_ERROR;
403 while (sqlite3_step(stmt) == SQLITE_ROW) {
405 _save_column_str(stmt, 0, &privilege);
407 *privileges = g_list_append(*privileges,
408 (gpointer)privilege);
411 sqlite3_finalize(stmt);
416 static char *_get_filtered_query(const char *query_raw,
417 pkgmgrinfo_filter_x *filter)
419 char buf[MAX_QUERY_LEN] = { 0, };
428 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
430 for (list = head; list; list = list->next) {
431 /* TODO: revise condition getter function */
432 __get_filter_condition(list->data, &condition);
433 if (condition == NULL)
435 if (buf[strlen(query_raw)] == '\0') {
436 len += strlen(" WHERE ");
437 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
439 len += strlen(" AND ");
440 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
442 len += strlen(condition);
443 strncat(buf, condition, sizeof(buf) - len - 1);
451 static void __free_packages(gpointer data)
453 pkgmgrinfo_basic_free_package((package_x *)data);
456 static int _pkginfo_get_packages(uid_t uid, const char *locale,
457 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
459 static const char query_raw[] =
460 "SELECT DISTINCT pi.package, pi.package_version, "
461 "pi.install_location, pi.package_removable, "
462 "pi.package_preload, pi.package_readonly, pi.package_update, "
463 "pi.package_appsetting, pi.package_system, pi.package_type, "
464 "pi.package_size, pi.installed_time, pi.installed_storage, "
465 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
466 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
467 "pi.package_api_version, pi.package_support_disable, "
468 "pi.package_tep_name, pi.package_zip_mount_file "
469 "FROM package_info as pi "
470 "WHERE pi.package_disable='false'";
479 dbpath = getUserPkgParserDBPathUID(uid);
481 return PMINFO_R_ERROR;
483 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
484 if (ret != SQLITE_OK) {
485 _LOGE("failed to open db: %d", ret);
486 return PMINFO_R_ERROR;
489 query = _get_filtered_query(query_raw, filter);
491 LOGE("out of memory");
492 sqlite3_close_v2(db);
493 return PMINFO_R_ERROR;
496 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
498 if (ret != SQLITE_OK) {
499 LOGE("prepare failed: %s", sqlite3_errmsg(db));
500 sqlite3_close_v2(db);
501 return PMINFO_R_ERROR;
504 while (sqlite3_step(stmt) == SQLITE_ROW) {
505 info = calloc(1, sizeof(package_x));
507 LOGE("out of memory");
508 sqlite3_finalize(stmt);
509 sqlite3_close_v2(db);
510 return PMINFO_R_ERROR;
513 _save_column_str(stmt, idx++, &info->package);
514 if (g_hash_table_contains(packages,
515 (gconstpointer)info->package)) {
520 _save_column_str(stmt, idx++, &info->version);
521 _save_column_str(stmt, idx++, &info->installlocation);
522 _save_column_str(stmt, idx++, &info->removable);
523 _save_column_str(stmt, idx++, &info->preload);
524 _save_column_str(stmt, idx++, &info->readonly);
525 _save_column_str(stmt, idx++, &info->update);
526 _save_column_str(stmt, idx++, &info->appsetting);
527 _save_column_str(stmt, idx++, &info->system);
528 _save_column_str(stmt, idx++, &info->type);
529 _save_column_str(stmt, idx++, &info->package_size);
530 _save_column_str(stmt, idx++, &info->installed_time);
531 _save_column_str(stmt, idx++, &info->installed_storage);
532 _save_column_str(stmt, idx++, &info->storeclient_id);
533 _save_column_str(stmt, idx++, &info->mainapp_id);
534 _save_column_str(stmt, idx++, &info->package_url);
535 _save_column_str(stmt, idx++, &info->root_path);
536 _save_column_str(stmt, idx++, &info->csc_path);
537 _save_column_str(stmt, idx++, &info->nodisplay_setting);
538 _save_column_str(stmt, idx++, &info->api_version);
539 _save_column_str(stmt, idx++, &info->support_disable);
540 _save_column_str(stmt, idx++, &info->tep_name);
541 _save_column_str(stmt, idx++, &info->zip_mount_file);
542 info->for_all_users =
543 strdup((uid != GLOBAL_USER) ? "false" : "true");
545 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
546 if (_pkginfo_get_author(db, info->package,
548 pkgmgrinfo_basic_free_package(info);
549 sqlite3_finalize(stmt);
550 sqlite3_close_v2(db);
551 return PMINFO_R_ERROR;
555 if (flag & PMINFO_PKGINFO_GET_LABEL) {
556 if (_pkginfo_get_label(db, info->package, locale,
558 pkgmgrinfo_basic_free_package(info);
559 sqlite3_finalize(stmt);
560 sqlite3_close_v2(db);
561 return PMINFO_R_ERROR;
565 if (flag & PMINFO_PKGINFO_GET_ICON) {
566 if (_pkginfo_get_icon(db, info->package, locale,
568 pkgmgrinfo_basic_free_package(info);
569 sqlite3_finalize(stmt);
570 sqlite3_close_v2(db);
571 return PMINFO_R_ERROR;
575 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
576 if (_pkginfo_get_description(db, info->package, locale,
577 &info->description)) {
578 pkgmgrinfo_basic_free_package(info);
579 sqlite3_finalize(stmt);
580 sqlite3_close_v2(db);
581 return PMINFO_R_ERROR;
585 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
586 if (_pkginfo_get_privilege(db, info->package,
587 &info->privileges)) {
588 pkgmgrinfo_basic_free_package(info);
589 sqlite3_finalize(stmt);
590 sqlite3_close_v2(db);
591 return PMINFO_R_ERROR;
595 g_hash_table_insert(packages, (gpointer)info->package,
599 sqlite3_finalize(stmt);
600 sqlite3_close_v2(db);
605 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
606 pkgmgrinfo_filter_x *filter, int flag,
607 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
612 pkgmgr_pkginfo_x info;
617 locale = _get_system_locale();
619 return PMINFO_R_ERROR;
621 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
625 return PMINFO_R_ERROR;
628 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
629 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
630 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
633 if (ret != PMINFO_R_OK) {
634 g_hash_table_destroy(list);
636 return PMINFO_R_ERROR;
639 g_hash_table_iter_init(&iter, list);
640 while (g_hash_table_iter_next(&iter, NULL, &value)) {
641 pkg = (package_x *)value;
644 info.locale = locale;
645 if (pkg_list_cb(&info, user_data) < 0)
649 g_hash_table_destroy(list);
655 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
656 pkgmgrinfo_pkginfo_h *handle)
661 pkgmgrinfo_pkginfo_filter_h filter;
662 pkgmgr_pkginfo_x *info;
664 if (pkgid == NULL || handle == NULL) {
665 LOGE("invalid parameter");
666 return PMINFO_R_EINVAL;
669 locale = _get_system_locale();
671 return PMINFO_R_ERROR;
673 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
674 if (ret != PMINFO_R_OK) {
679 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
680 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
681 if (ret != PMINFO_R_OK) {
682 pkgmgrinfo_pkginfo_filter_destroy(filter);
684 return PMINFO_R_ERROR;
687 list = g_hash_table_new(g_str_hash, g_str_equal);
689 pkgmgrinfo_pkginfo_filter_destroy(filter);
691 return PMINFO_R_ERROR;
694 ret = _pkginfo_get_packages(uid, locale, NULL,
695 PMINFO_PKGINFO_GET_ALL, list);
696 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
697 ret = _pkginfo_get_packages(GLOBAL_USER, locale, NULL,
698 PMINFO_PKGINFO_GET_ALL, list);
700 pkgmgrinfo_pkginfo_filter_destroy(filter);
701 if (ret != PMINFO_R_OK) {
702 g_hash_table_destroy(list);
707 if (!g_hash_table_size(list)) {
708 _LOGI("pkginfo for [%s] is not existed for user [%d]",
710 g_hash_table_destroy(list);
712 return PMINFO_R_ENOENT;
715 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
717 _LOGE("out of memory");
718 g_hash_table_destroy(list);
720 return PMINFO_R_ERROR;
724 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
725 info->locale = locale;
727 /* just free list only */
728 g_hash_table_destroy(list);
735 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
736 pkgmgrinfo_pkginfo_h *handle)
738 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
741 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
742 int flag, void *user_data, uid_t uid)
744 if (pkg_list_cb == NULL) {
745 LOGE("invalid parameter");
746 return PMINFO_R_EINVAL;
749 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
750 pkg_list_cb, user_data);
753 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
754 int flag, void *user_data)
756 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
757 user_data, _getuid());
760 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
761 void *user_data, uid_t uid)
763 if (pkg_list_cb == NULL) {
764 LOGE("invalid parameter");
765 return PMINFO_R_EINVAL;
768 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
769 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
772 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
775 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
779 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
781 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
783 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
784 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
786 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
787 return PMINFO_R_ERROR;
789 *pkg_name = (char *)info->pkg_info->package;
794 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
796 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
798 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
799 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
801 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
802 return PMINFO_R_ERROR;
804 *pkgid = (char *)info->pkg_info->package;
809 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
811 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
814 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
816 if (info->pkg_info == NULL || info->pkg_info->type == NULL)
817 return PMINFO_R_ERROR;
819 *type = (char *)info->pkg_info->type;
824 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
826 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
829 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
831 if (info->pkg_info == NULL || info->pkg_info->version == NULL)
832 return PMINFO_R_ERROR;
834 *version = (char *)info->pkg_info->version;
839 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
841 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
844 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
846 if (info->pkg_info == NULL || info->pkg_info->api_version == NULL)
847 return PMINFO_R_ERROR;
849 *api_version = (char *)info->pkg_info->api_version;
854 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_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(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
861 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
862 return PMINFO_R_ERROR;
864 if (strlen(info->pkg_info->tep_name) == 0)
865 return PMINFO_R_ERROR;
867 *tep_name = (char *)info->pkg_info->tep_name;
872 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
874 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
876 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
877 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
879 if (info->pkg_info == NULL)
880 return PMINFO_R_ERROR;
882 if (strlen(info->pkg_info->zip_mount_file) > 0)
883 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
888 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
891 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
894 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
896 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
897 return PMINFO_R_ERROR;
899 val = (char *)info->pkg_info->installlocation;
900 if (strcmp(val, "internal-only") == 0)
901 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
902 else if (strcmp(val, "prefer-external") == 0)
903 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
905 *location = PMINFO_INSTALL_LOCATION_AUTO;
910 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
912 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
914 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
915 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
917 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
918 return PMINFO_R_ERROR;
920 *size = atoi((char *)info->pkg_info->package_size);
925 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
928 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
929 long long rw_size = 0;
930 long long ro_size = 0;
931 long long tmp_size = 0;
932 long long total_size = 0;
933 struct stat fileinfo;
936 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
937 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
939 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
941 return PMINFO_R_ERROR;
944 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
945 if (lstat(device_path, &fileinfo) == 0) {
946 if (!S_ISLNK(fileinfo.st_mode)) {
947 tmp_size = _pkgmgr_calculate_dir_size(device_path);
953 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
954 if (lstat(device_path, &fileinfo) == 0) {
955 if (!S_ISLNK(fileinfo.st_mode)) {
956 tmp_size = _pkgmgr_calculate_dir_size(device_path);
962 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
963 if (lstat(device_path, &fileinfo) == 0) {
964 if (!S_ISLNK(fileinfo.st_mode)) {
965 tmp_size = _pkgmgr_calculate_dir_size(device_path);
971 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
972 if (lstat(device_path, &fileinfo) == 0) {
973 if (!S_ISLNK(fileinfo.st_mode)) {
974 tmp_size = _pkgmgr_calculate_dir_size(device_path);
980 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
981 if (lstat(device_path, &fileinfo) == 0) {
982 if (!S_ISLNK(fileinfo.st_mode)) {
983 tmp_size = _pkgmgr_calculate_dir_size(device_path);
989 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
990 if (lstat(device_path, &fileinfo) == 0) {
991 if (!S_ISLNK(fileinfo.st_mode)) {
992 tmp_size = _pkgmgr_calculate_dir_size(device_path);
999 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
1000 if (lstat(device_path, &fileinfo) == 0) {
1001 if (!S_ISLNK(fileinfo.st_mode)) {
1002 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1004 ro_size += tmp_size;
1008 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
1009 if (lstat(device_path, &fileinfo) == 0) {
1010 if (!S_ISLNK(fileinfo.st_mode)) {
1011 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1013 ro_size += tmp_size;
1017 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
1018 if (lstat(device_path, &fileinfo) == 0) {
1019 if (!S_ISLNK(fileinfo.st_mode)) {
1020 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1022 ro_size += tmp_size;
1026 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
1027 if (lstat(device_path, &fileinfo) == 0) {
1028 if (!S_ISLNK(fileinfo.st_mode)) {
1029 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1031 ro_size += tmp_size;
1035 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
1036 if (lstat(device_path, &fileinfo) == 0) {
1037 if (!S_ISLNK(fileinfo.st_mode)) {
1038 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1040 ro_size += tmp_size;
1044 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
1045 if (lstat(device_path, &fileinfo) == 0) {
1046 if (!S_ISLNK(fileinfo.st_mode)) {
1047 tmp_size = _pkgmgr_calculate_dir_size(device_path);
1049 ro_size += tmp_size;
1054 total_size = rw_size + ro_size;
1055 *size = (int)total_size;
1060 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1063 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1064 long long total_size = 0;
1066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1067 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1069 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1070 return PMINFO_R_ERROR;
1072 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1073 if (access(device_path, R_OK) == 0)
1074 total_size = _pkgmgr_calculate_dir_size(device_path);
1076 return PMINFO_R_ERROR;
1078 *size = (int)total_size;
1083 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1088 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1091 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1093 locale = info->locale;
1094 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1096 if (info->pkg_info == NULL)
1097 return PMINFO_R_ERROR;
1099 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1100 ptr = (icon_x *)tmp->data;
1101 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1102 !strcasecmp(ptr->text, "(null)") ||
1103 strcmp(ptr->lang, locale))
1105 *icon = (char *)ptr->text;
1109 locale = DEFAULT_LOCALE;
1110 for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
1111 ptr = (icon_x *)tmp->data;
1112 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1113 strcmp(ptr->lang, locale))
1115 *icon = (char *)ptr->text;
1119 return PMINFO_R_ERROR;
1122 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1127 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1130 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1132 locale = info->locale;
1133 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1135 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1136 ptr = (label_x *)tmp->data;
1137 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1138 strcmp(ptr->lang, locale))
1140 *label = (char *)ptr->text;
1144 locale = DEFAULT_LOCALE;
1145 for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
1146 ptr = (label_x *)tmp->data;
1147 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1148 strcmp(ptr->lang, locale))
1150 *label = (char *)ptr->text;
1154 return PMINFO_R_ERROR;
1157 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1162 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1164 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1165 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1167 locale = info->locale;
1168 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1170 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1171 ptr = (description_x *)tmp->data;
1172 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1173 strcmp(ptr->lang, locale))
1175 *description = (char *)ptr->text;
1179 locale = DEFAULT_LOCALE;
1180 for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
1181 ptr = (description_x *)tmp->data;
1182 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1183 strcmp(ptr->lang, locale))
1185 *description = (char *)ptr->text;
1189 return PMINFO_R_ERROR;
1192 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1194 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1197 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1198 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1200 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1201 return PMINFO_R_ERROR;
1203 author = (author_x *)info->pkg_info->author->data;
1204 if (author == NULL || author->text == NULL)
1205 return PMINFO_R_ERROR;
1207 *author_name = (char *)author->text;
1212 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1214 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1218 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1220 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1221 return PMINFO_R_ERROR;
1223 author = (author_x *)info->pkg_info->author->data;
1224 if (author == NULL || author->email == NULL)
1225 return PMINFO_R_ERROR;
1227 *author_email = (char *)author->email;
1232 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1234 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1238 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1240 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1241 return PMINFO_R_ERROR;
1243 author = (author_x *)info->pkg_info->author->data;
1244 if (author == NULL || author->href == NULL)
1245 return PMINFO_R_ERROR;
1247 *author_href = (char *)author->href;
1252 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1254 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1256 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1257 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1259 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1260 return PMINFO_R_ERROR;
1262 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1263 *storage = PMINFO_INTERNAL_STORAGE;
1264 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1265 *storage = PMINFO_EXTERNAL_STORAGE;
1267 return PMINFO_R_ERROR;
1272 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1274 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1276 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1277 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1279 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1280 return PMINFO_R_ERROR;
1282 *installed_time = atoi(info->pkg_info->installed_time);
1287 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1289 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1291 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1292 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1294 if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
1295 return PMINFO_R_ERROR;
1297 *storeclientid = (char *)info->pkg_info->storeclient_id;
1302 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1304 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1306 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1307 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1309 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1310 return PMINFO_R_ERROR;
1312 *mainappid = (char *)info->pkg_info->mainapp_id;
1317 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1319 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1322 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1324 if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
1325 return PMINFO_R_ERROR;
1327 *url = (char *)info->pkg_info->package_url;
1332 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1334 const char *val = NULL;
1335 const xmlChar *node;
1336 xmlTextReaderPtr reader;
1337 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1338 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1341 reader = xmlReaderForFile(manifest, NULL, 0);
1344 if (__child_element(reader, -1)) {
1345 node = xmlTextReaderConstName(reader);
1347 _LOGE("xmlTextReaderConstName value is NULL\n");
1348 xmlFreeTextReader(reader);
1350 return PMINFO_R_ERROR;
1353 if (!strcmp(ASC_CHAR(node), "manifest")) {
1354 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1355 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1361 _LOGE("package size is not specified\n");
1362 xmlFreeTextReader(reader);
1364 return PMINFO_R_ERROR;
1367 _LOGE("Unable to create xml reader\n");
1368 xmlFreeTextReader(reader);
1370 return PMINFO_R_ERROR;
1374 _LOGE("xmlReaderForFile value is NULL\n");
1376 return PMINFO_R_ERROR;
1379 xmlFreeTextReader(reader);
1385 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1387 const char *val = NULL;
1388 const xmlChar *node;
1389 xmlTextReaderPtr reader;
1390 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1391 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1394 reader = xmlReaderForFile(manifest, NULL, 0);
1397 if ( __child_element(reader, -1)) {
1398 node = xmlTextReaderConstName(reader);
1400 _LOGE("xmlTextReaderConstName value is NULL\n");
1401 xmlFreeTextReader(reader);
1403 return PMINFO_R_ERROR;
1406 if (!strcmp(ASC_CHAR(node), "manifest")) {
1407 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1408 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1411 if (strcmp(val, "internal-only") == 0)
1412 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1413 else if (strcmp(val, "prefer-external") == 0)
1414 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1416 *location = PMINFO_INSTALL_LOCATION_AUTO;
1419 _LOGE("Unable to create xml reader\n");
1420 xmlFreeTextReader(reader);
1422 return PMINFO_R_ERROR;
1426 _LOGE("xmlReaderForFile value is NULL\n");
1428 return PMINFO_R_ERROR;
1431 xmlFreeTextReader(reader);
1438 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1440 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1443 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1445 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1446 return PMINFO_R_ERROR;
1448 *path = (char *)info->pkg_info->root_path;
1453 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1455 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1457 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1458 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1460 if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
1461 return PMINFO_R_ERROR;
1463 *path = (char *)info->pkg_info->csc_path;
1469 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1472 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1474 #if 0 //smack issue occured, check later
1476 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1478 _LOGD("invalid func parameters\n");
1479 return PMINFO_R_ERROR;
1481 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1484 char app_mmc_path[FILENAME_MAX] = { 0, };
1485 char app_dir_path[FILENAME_MAX] = { 0, };
1486 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1487 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1488 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1489 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1491 /*check whether application is in external memory or not */
1492 fp = fopen(app_mmc_path, "r");
1494 _LOGD(" app path in external memory not accesible\n");
1499 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1503 /*check whether application is in internal or not */
1504 fp = fopen(app_dir_path, "r");
1506 _LOGD(" app path in internal memory not accesible\n");
1508 return PMINFO_R_ERROR;
1511 /*check whether the application is installed in SD card
1512 but SD card is not present*/
1513 fp = fopen(app_mmc_internal_path, "r");
1516 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1521 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1526 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1533 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1535 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1538 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1540 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1541 return PMINFO_R_ERROR;
1543 *removable = _get_bool_value(info->pkg_info->removable);
1548 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1551 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1553 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1554 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1556 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1557 return PMINFO_R_ERROR;
1559 val = (char *)info->pkg_info->installlocation;
1560 if (strcmp(val, "internal-only") == 0)
1562 else if (strcmp(val, "prefer-external") == 0)
1570 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1572 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1574 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1575 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1577 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1578 return PMINFO_R_ERROR;
1580 *preload = _get_bool_value(info->pkg_info->preload);
1585 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1587 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1589 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1590 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1592 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1593 return PMINFO_R_ERROR;
1595 *system = _get_bool_value(info->pkg_info->system);
1600 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1602 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1604 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1605 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1607 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1608 return PMINFO_R_ERROR;
1610 *readonly = _get_bool_value(info->pkg_info->readonly);
1615 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1617 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1619 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1620 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1622 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1623 return PMINFO_R_ERROR;
1625 *update = _get_bool_value(info->pkg_info->update);
1630 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1632 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1634 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1635 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1637 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1638 return PMINFO_R_ERROR;
1640 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1645 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
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(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1652 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1653 return PMINFO_R_ERROR;
1655 *global = _get_bool_value(info->pkg_info->for_all_users);
1660 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1662 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1665 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1667 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1669 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1671 __cleanup_pkginfo(info);
1676 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1678 pkgmgrinfo_filter_x *filter;
1680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1682 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1683 if (filter == NULL) {
1684 _LOGE("Out of Memory!!!");
1685 return PMINFO_R_ERROR;
1693 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1695 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1697 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1700 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1701 g_slist_free(filter->list);
1709 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1710 const char *property, const int value)
1712 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1716 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1717 pkgmgrinfo_node_x *node;
1719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1720 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1722 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1723 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1724 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1725 _LOGE("Invalid Integer Property\n");
1726 return PMINFO_R_EINVAL;
1728 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1730 _LOGE("Out of Memory!!!\n");
1731 return PMINFO_R_ERROR;
1733 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1734 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1736 _LOGE("Out of Memory\n");
1738 return PMINFO_R_ERROR;
1742 /*If API is called multiple times for same property, we should override the previous values.
1743 Last value set will be used for filtering.*/
1744 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1746 filter->list = g_slist_delete_link(filter->list, link);
1747 filter->list = g_slist_append(filter->list, (gpointer)node);
1752 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1753 const char *property, const bool value)
1758 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1759 pkgmgrinfo_node_x *node;
1761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1762 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1764 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1765 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1766 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1767 _LOGE("Invalid Boolean Property\n");
1768 return PMINFO_R_EINVAL;
1770 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1772 _LOGE("Out of Memory!!!\n");
1773 return PMINFO_R_ERROR;
1776 val = strndup("('true','True')", 15);
1778 val = strndup("('false','False')", 17);
1780 _LOGE("Out of Memory\n");
1782 return PMINFO_R_ERROR;
1786 /*If API is called multiple times for same property, we should override the previous values.
1787 Last value set will be used for filtering.*/
1788 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1790 filter->list = g_slist_delete_link(filter->list, link);
1791 filter->list = g_slist_append(filter->list, (gpointer)node);
1796 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1797 const char *property, const char *value)
1802 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1803 pkgmgrinfo_node_x *node;
1805 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1806 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1807 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1809 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1810 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1811 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1812 _LOGE("Invalid String Property\n");
1813 return PMINFO_R_EINVAL;
1815 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1817 _LOGE("Out of Memory!!!\n");
1818 return PMINFO_R_ERROR;
1820 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1821 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1822 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1823 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1824 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1825 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1826 else if (strcmp(value, "installed_internal") == 0)
1827 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1828 else if (strcmp(value, "installed_external") == 0)
1829 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1831 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1833 _LOGE("Out of Memory\n");
1835 return PMINFO_R_ERROR;
1839 /*If API is called multiple times for same property, we should override the previous values.
1840 Last value set will be used for filtering.*/
1841 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1843 filter->list = g_slist_delete_link(filter->list, link);
1844 filter->list = g_slist_append(filter->list, (gpointer)node);
1849 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1853 GHashTable *list = NULL;
1855 if (handle == NULL || count == NULL) {
1856 _LOGE("invalid parameter");
1857 return PMINFO_R_EINVAL;
1860 locale = _get_system_locale();
1862 return PMINFO_R_ERROR;
1864 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1868 return PMINFO_R_ERROR;
1871 ret = _pkginfo_get_packages(uid, locale,
1872 (pkgmgrinfo_filter_x *)handle, 0, list);
1873 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1874 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1877 if (ret != PMINFO_R_OK) {
1878 g_hash_table_destroy(list);
1880 return PMINFO_R_ERROR;
1883 *count = g_hash_table_size(list);
1885 g_hash_table_destroy(list);
1891 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1893 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1896 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1897 pkgmgrinfo_pkginfo_filter_h handle,
1898 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1900 if (handle == NULL || pkg_cb == NULL) {
1901 LOGE("invalid parameter");
1902 return PMINFO_R_EINVAL;
1905 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1906 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1909 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1910 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1912 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1915 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1916 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1919 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1921 const char *privilege;
1923 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1925 if (info->pkg_info == NULL)
1926 return PMINFO_R_ERROR;
1928 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1929 privilege = (const char *)tmp->data;
1930 if (privilege == NULL)
1932 ret = privilege_func(privilege, user_data);