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.
29 #include <sys/smack.h>
30 #include <linux/limits.h>
34 #include <libxml/parser.h>
35 #include <libxml/xmlreader.h>
36 #include <libxml/xmlschemas.h>
40 #include "pkgmgr_parser.h"
41 #include "pkgmgrinfo_basic.h"
42 #include "pkgmgrinfo_private.h"
43 #include "pkgmgrinfo_debug.h"
44 #include "pkgmgr-info.h"
45 #include "pkgmgr_parser_db.h"
46 #include "pkgmgr_parser_internal.h"
48 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
49 "from package_info LEFT OUTER JOIN package_localized_info " \
50 "ON package_info.package=package_localized_info.package " \
51 "and package_localized_info.package_locale='%s' where "
54 static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
55 pkgmgr_pkginfo_x **pkginfo);
56 static char *_get_filtered_query(const char *query_raw,
57 pkgmgrinfo_filter_x *filter);
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 int __count_cb(void *data, int ncols, char **coltxt, char **colname)
75 _LOGE("count value is %d\n", *p);
79 static void __destroy_each_node(gpointer data, gpointer user_data)
82 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
95 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
99 free((void *)data->locale);
103 pkgmgrinfo_basic_free_package(data->pkg_info);
109 static int __child_element(xmlTextReaderPtr reader, int depth)
111 int ret = xmlTextReaderRead(reader);
112 int cur = xmlTextReaderDepth(reader);
115 switch (xmlTextReaderNodeType(reader)) {
116 case XML_READER_TYPE_ELEMENT:
117 if (cur == depth + 1)
120 case XML_READER_TYPE_TEXT:
121 /*text is handled by each function separately*/
122 if (cur == depth + 1)
125 case XML_READER_TYPE_END_ELEMENT:
134 ret = xmlTextReaderRead(reader);
135 cur = xmlTextReaderDepth(reader);
140 long long _pkgmgr_calculate_dir_size(char *dirname)
144 int q = 0; /*quotient*/
145 int r = 0; /*remainder*/
147 struct dirent *ep = NULL;
148 struct stat fileinfo;
149 char abs_filename[FILENAME_MAX] = { 0, };
150 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
152 dp = opendir(dirname);
154 while ((ep = readdir(dp)) != NULL) {
155 if (!strcmp(ep->d_name, ".") ||
156 !strcmp(ep->d_name, "..")) {
159 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
161 if (lstat(abs_filename, &fileinfo) < 0)
162 perror(abs_filename);
164 if (S_ISDIR(fileinfo.st_mode)) {
165 total += fileinfo.st_size;
166 if (strcmp(ep->d_name, ".")
167 && strcmp(ep->d_name, "..")) {
168 ret = _pkgmgr_calculate_dir_size
172 } else if (S_ISLNK(fileinfo.st_mode)) {
175 /*It is a file. Calculate the actual
176 size occupied (in terms of 4096 blocks)*/
177 q = (fileinfo.st_size / BLOCK_SIZE);
178 r = (fileinfo.st_size % BLOCK_SIZE);
182 total += q * BLOCK_SIZE;
188 _LOGE("Couldn't open the directory\n");
195 static GSList *_pkginfo_get_filtered_list(const char *locale,
196 pkgmgrinfo_filter_x *filter)
198 static const char query_raw[] =
199 "SELECT package_info.package FROM package_info"
200 " LEFT OUTER JOIN package_localized_info"
201 " ON package_info.package=package_localized_info.package"
202 " AND package_localized_info.package_locale=%Q ";
205 char *query_localized;
210 query = _get_filtered_query(query_raw, filter);
213 query_localized = sqlite3_mprintf(query, locale);
215 if (query_localized == NULL)
218 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
219 strlen(query_localized), &stmt, NULL);
220 sqlite3_free(query_localized);
221 if (ret != SQLITE_OK) {
222 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
226 while (sqlite3_step(stmt) == SQLITE_ROW) {
227 _save_column_str(stmt, 0, (const char **)&pkgid);
228 list = g_slist_append(list, pkgid);
231 sqlite3_finalize(stmt);
236 static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
237 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
239 pkgmgr_pkginfo_x *info;
246 if (__open_manifest_db(uid) < 0)
247 return PMINFO_R_ERROR;
249 locale = _get_system_locale();
250 if (locale == NULL) {
251 __close_manifest_db();
252 return PMINFO_R_ERROR;
255 list = _pkginfo_get_filtered_list(locale, filter);
258 __close_manifest_db();
262 for (tmp = list; tmp; tmp = tmp->next) {
263 pkgid = (char *)tmp->data;
265 if (_pkginfo_get_pkg(pkgid, locale, &info)) {
269 if (pkg_list_cb(info, user_data) < 0)
271 pkgmgrinfo_pkginfo_destroy_pkginfo(info);
278 __close_manifest_db();
283 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
284 void *user_data, uid_t uid)
286 if (pkg_list_cb == NULL) {
287 LOGE("invalid parameter");
288 return PMINFO_R_EINVAL;
291 return _pkginfo_get_filtered_foreach_pkginfo(NULL, pkg_list_cb,
295 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
297 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
300 static int _pkginfo_get_author(const char *pkgid, author_x **author)
302 static const char query_raw[] =
303 "SELECT author_name, author_email, author_href "
304 "FROM package_info WHERE package=%Q";
311 query = sqlite3_mprintf(query_raw, pkgid);
313 LOGE("out of memory");
314 return PMINFO_R_ERROR;
317 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
320 if (ret != SQLITE_OK) {
321 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
322 return PMINFO_R_ERROR;
325 if (sqlite3_step(stmt) == SQLITE_ERROR) {
326 LOGE("step error: %s", sqlite3_errmsg(GET_DB(manifest_db)));
327 sqlite3_finalize(stmt);
328 return PMINFO_R_ERROR;
331 /* one author per one package */
332 info = calloc(1, sizeof(author_x));
334 LOGE("out of memory");
335 sqlite3_finalize(stmt);
336 return PMINFO_R_ERROR;
339 _save_column_str(stmt, idx++, &info->text);
340 _save_column_str(stmt, idx++, &info->email);
341 _save_column_str(stmt, idx++, &info->href);
345 sqlite3_finalize(stmt);
350 static int _pkginfo_get_label(const char *pkgid, const char *locale,
353 static const char query_raw[] =
354 "SELECT package_label, package_locale "
355 "FROM package_localized_info "
356 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
363 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
365 LOGE("out of memory");
366 return PMINFO_R_ERROR;
369 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
372 if (ret != SQLITE_OK) {
373 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
374 return PMINFO_R_ERROR;
377 while (sqlite3_step(stmt) == SQLITE_ROW) {
378 info = calloc(1, sizeof(label_x));
380 LOGE("out of memory");
381 sqlite3_finalize(stmt);
383 LISTHEAD(*label, info);
386 return PMINFO_R_ERROR;
389 _save_column_str(stmt, idx++, &info->text);
390 _save_column_str(stmt, idx++, &info->lang);
391 LISTADD(*label, info);
395 LISTHEAD(*label, info);
399 sqlite3_finalize(stmt);
404 static int _pkginfo_get_icon(const char *pkgid, const char *locale,
407 static const char query_raw[] =
408 "SELECT package_icon, package_locale "
409 "FROM package_localized_info "
410 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
417 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
419 LOGE("out of memory");
420 return PMINFO_R_ERROR;
423 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
426 if (ret != SQLITE_OK) {
427 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
428 return PMINFO_R_ERROR;
431 while (sqlite3_step(stmt) == SQLITE_ROW) {
432 info = calloc(1, sizeof(icon_x));
434 LOGE("out of memory");
435 sqlite3_finalize(stmt);
437 LISTHEAD(*icon, info);
440 return PMINFO_R_ERROR;
443 _save_column_str(stmt, idx++, &info->text);
444 _save_column_str(stmt, idx++, &info->lang);
445 LISTADD(*icon, info);
449 LISTHEAD(*icon, info);
453 sqlite3_finalize(stmt);
458 static int _pkginfo_get_description(const char *pkgid, const char *locale,
459 description_x **description)
461 static const char query_raw[] =
462 "SELECT package_description, package_locale "
463 "FROM package_localized_info "
464 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
471 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
473 LOGE("out of memory");
474 return PMINFO_R_ERROR;
477 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
480 if (ret != SQLITE_OK) {
481 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
482 return PMINFO_R_ERROR;
485 while (sqlite3_step(stmt) == SQLITE_ROW) {
486 info = calloc(1, sizeof(description_x));
488 LOGE("out of memory");
489 sqlite3_finalize(stmt);
491 LISTHEAD(*description, info);
494 return PMINFO_R_ERROR;
497 _save_column_str(stmt, idx++, &info->text);
498 _save_column_str(stmt, idx++, &info->lang);
499 LISTADD(*description, info);
503 LISTHEAD(*description, info);
507 sqlite3_finalize(stmt);
512 static int _pkginfo_get_privilege(const char *pkgid, privileges_x **privileges)
514 static const char query_raw[] =
515 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
522 /* privilege list should stored in privileges_x... */
523 p = calloc(1, sizeof(privileges_x));
525 LOGE("out of memory");
526 return PMINFO_R_ERROR;
530 query = sqlite3_mprintf(query_raw, pkgid);
532 LOGE("out of memory");
534 return PMINFO_R_ERROR;
537 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
540 if (ret != SQLITE_OK) {
541 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
543 return PMINFO_R_ERROR;
546 while (sqlite3_step(stmt) == SQLITE_ROW) {
547 info = calloc(1, sizeof(privilege_x));
549 LOGE("out of memory");
550 sqlite3_finalize(stmt);
552 LISTHEAD(p->privilege, info);
555 return PMINFO_R_ERROR;
557 _save_column_str(stmt, 0, &info->text);
558 LISTADD(p->privilege, info);
562 LISTHEAD(p->privilege, info);
566 sqlite3_finalize(stmt);
571 static char *_get_filtered_query(const char *query_raw,
572 pkgmgrinfo_filter_x *filter)
574 char buf[MAX_QUERY_LEN] = { 0, };
583 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
585 for (list = head; list; list = list->next) {
586 /* TODO: revise condition getter function */
587 __get_filter_condition(list->data, &condition);
588 if (condition == NULL)
590 if (buf[strlen(query_raw)] == '\0') {
591 len += strlen(" WHERE ");
592 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
594 len += strlen(" AND ");
595 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
597 len += strlen(condition);
598 strncat(buf, condition, sizeof(buf) - len - 1);
606 static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
607 pkgmgr_pkginfo_x **pkginfo)
609 static const char query_raw[] =
610 "SELECT for_all_users, package, package_version, "
611 "install_location, package_removable, package_preload, "
612 "package_readonly, package_update, package_appsetting, "
613 "package_system, package_type, package_size, installed_time, "
614 "installed_storage, storeclient_id, mainapp_id, package_url, "
615 "root_path, csc_path, package_nodisplay, package_api_version "
616 "FROM package_info WHERE package=%Q";
621 pkgmgr_pkginfo_x *info;
624 query = sqlite3_mprintf(query_raw, pkgid);
626 LOGE("out of memory");
627 return PMINFO_R_ERROR;
630 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
633 if (ret != SQLITE_OK) {
634 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
635 return PMINFO_R_ERROR;
638 ret = sqlite3_step(stmt);
639 if (ret == SQLITE_DONE) {
640 LOGE("cannot find pkg");
641 sqlite3_finalize(stmt);
642 return PMINFO_R_ENOENT;
643 } else if (ret != SQLITE_ROW) {
644 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
645 sqlite3_finalize(stmt);
646 return PMINFO_R_ERROR;
649 pkg = calloc(1, sizeof(package_x));
651 LOGE("out of memory");
652 sqlite3_finalize(stmt);
653 return PMINFO_R_ERROR;
656 _save_column_str(stmt, idx++, &pkg->for_all_users);
657 _save_column_str(stmt, idx++, &pkg->package);
658 _save_column_str(stmt, idx++, &pkg->version);
659 _save_column_str(stmt, idx++, &pkg->installlocation);
660 _save_column_str(stmt, idx++, &pkg->removable);
661 _save_column_str(stmt, idx++, &pkg->preload);
662 _save_column_str(stmt, idx++, &pkg->readonly);
663 _save_column_str(stmt, idx++, &pkg->update);
664 _save_column_str(stmt, idx++, &pkg->appsetting);
665 _save_column_str(stmt, idx++, &pkg->system);
666 _save_column_str(stmt, idx++, &pkg->type);
667 _save_column_str(stmt, idx++, &pkg->package_size);
668 _save_column_str(stmt, idx++, &pkg->installed_time);
669 _save_column_str(stmt, idx++, &pkg->installed_storage);
670 _save_column_str(stmt, idx++, &pkg->storeclient_id);
671 _save_column_str(stmt, idx++, &pkg->mainapp_id);
672 _save_column_str(stmt, idx++, &pkg->package_url);
673 _save_column_str(stmt, idx++, &pkg->root_path);
674 _save_column_str(stmt, idx++, &pkg->csc_path);
675 _save_column_str(stmt, idx++, &pkg->nodisplay_setting);
676 _save_column_str(stmt, idx++, &pkg->api_version);
678 if (_pkginfo_get_author(pkg->package, &pkg->author)) {
679 pkgmgrinfo_basic_free_package(pkg);
680 sqlite3_finalize(stmt);
681 return PMINFO_R_ERROR;
684 if (_pkginfo_get_label(pkg->package, locale, &pkg->label)) {
685 pkgmgrinfo_basic_free_package(pkg);
686 sqlite3_finalize(stmt);
687 return PMINFO_R_ERROR;
690 if (_pkginfo_get_icon(pkg->package, locale, &pkg->icon)) {
691 pkgmgrinfo_basic_free_package(pkg);
692 sqlite3_finalize(stmt);
693 return PMINFO_R_ERROR;
696 if (_pkginfo_get_description(pkg->package, locale,
697 &pkg->description)) {
698 pkgmgrinfo_basic_free_package(pkg);
699 sqlite3_finalize(stmt);
700 return PMINFO_R_ERROR;
703 if (_pkginfo_get_privilege(pkg->package, &pkg->privileges)) {
704 pkgmgrinfo_basic_free_package(pkg);
705 sqlite3_finalize(stmt);
706 return PMINFO_R_ERROR;
709 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
711 LOGE("out of memory");
712 pkgmgrinfo_basic_free_package(pkg);
713 sqlite3_finalize(stmt);
714 return PMINFO_R_ERROR;
717 info->pkg_info = pkg;
720 sqlite3_finalize(stmt);
725 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
726 pkgmgrinfo_pkginfo_h *handle)
728 pkgmgr_pkginfo_x *pkginfo = NULL;
731 if (pkgid == NULL || handle == NULL) {
732 LOGE("invalid parameter");
733 return PMINFO_R_EINVAL;
736 if (__open_manifest_db(uid) < 0)
737 return PMINFO_R_ERROR;
740 locale = _get_system_locale();
741 if (locale == NULL) {
742 __close_manifest_db();
743 return PMINFO_R_ERROR;
746 if (_pkginfo_get_pkg(pkgid, locale, &pkginfo)) {
747 LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
749 __close_manifest_db();
750 return PMINFO_R_ERROR;
754 pkginfo->locale = locale;
757 __close_manifest_db();
762 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
764 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
767 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
769 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
771 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
772 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
774 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
775 return PMINFO_R_ERROR;
777 *pkg_name = (char *)info->pkg_info->package;
782 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
784 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
786 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
787 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
789 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
790 return PMINFO_R_ERROR;
792 *pkgid = (char *)info->pkg_info->package;
797 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
799 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
801 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
802 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
804 if (info->pkg_info == NULL || info->pkg_info->type == NULL)
805 return PMINFO_R_ERROR;
807 *type = (char *)info->pkg_info->type;
812 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
814 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
816 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
817 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
819 if (info->pkg_info == NULL || info->pkg_info->version == NULL)
820 return PMINFO_R_ERROR;
822 *version = (char *)info->pkg_info->version;
827 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
830 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
833 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
835 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
836 return PMINFO_R_ERROR;
838 val = (char *)info->pkg_info->installlocation;
839 if (strcmp(val, "internal-only") == 0)
840 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
841 else if (strcmp(val, "prefer-external") == 0)
842 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
844 *location = PMINFO_INSTALL_LOCATION_AUTO;
849 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
851 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
853 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
854 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
856 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
857 return PMINFO_R_ERROR;
859 *size = atoi((char *)info->pkg_info->package_size);
864 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
867 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
868 long long rw_size = 0;
869 long long ro_size = 0;
870 long long tmp_size = 0;
871 long long total_size = 0;
872 struct stat fileinfo;
875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
876 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
878 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
880 return PMINFO_R_ERROR;
883 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
884 if (lstat(device_path, &fileinfo) == 0) {
885 if (!S_ISLNK(fileinfo.st_mode)) {
886 tmp_size = _pkgmgr_calculate_dir_size(device_path);
892 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
893 if (lstat(device_path, &fileinfo) == 0) {
894 if (!S_ISLNK(fileinfo.st_mode)) {
895 tmp_size = _pkgmgr_calculate_dir_size(device_path);
901 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
902 if (lstat(device_path, &fileinfo) == 0) {
903 if (!S_ISLNK(fileinfo.st_mode)) {
904 tmp_size = _pkgmgr_calculate_dir_size(device_path);
910 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
911 if (lstat(device_path, &fileinfo) == 0) {
912 if (!S_ISLNK(fileinfo.st_mode)) {
913 tmp_size = _pkgmgr_calculate_dir_size(device_path);
919 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
920 if (lstat(device_path, &fileinfo) == 0) {
921 if (!S_ISLNK(fileinfo.st_mode)) {
922 tmp_size = _pkgmgr_calculate_dir_size(device_path);
928 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
929 if (lstat(device_path, &fileinfo) == 0) {
930 if (!S_ISLNK(fileinfo.st_mode)) {
931 tmp_size = _pkgmgr_calculate_dir_size(device_path);
938 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
939 if (lstat(device_path, &fileinfo) == 0) {
940 if (!S_ISLNK(fileinfo.st_mode)) {
941 tmp_size = _pkgmgr_calculate_dir_size(device_path);
947 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
948 if (lstat(device_path, &fileinfo) == 0) {
949 if (!S_ISLNK(fileinfo.st_mode)) {
950 tmp_size = _pkgmgr_calculate_dir_size(device_path);
956 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
957 if (lstat(device_path, &fileinfo) == 0) {
958 if (!S_ISLNK(fileinfo.st_mode)) {
959 tmp_size = _pkgmgr_calculate_dir_size(device_path);
965 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
966 if (lstat(device_path, &fileinfo) == 0) {
967 if (!S_ISLNK(fileinfo.st_mode)) {
968 tmp_size = _pkgmgr_calculate_dir_size(device_path);
974 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
975 if (lstat(device_path, &fileinfo) == 0) {
976 if (!S_ISLNK(fileinfo.st_mode)) {
977 tmp_size = _pkgmgr_calculate_dir_size(device_path);
983 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
984 if (lstat(device_path, &fileinfo) == 0) {
985 if (!S_ISLNK(fileinfo.st_mode)) {
986 tmp_size = _pkgmgr_calculate_dir_size(device_path);
993 total_size = rw_size + ro_size;
994 *size = (int)total_size;
999 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1002 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1003 long long total_size = 0;
1005 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1006 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1008 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1009 return PMINFO_R_ERROR;
1011 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1012 if (access(device_path, R_OK) == 0)
1013 total_size = _pkgmgr_calculate_dir_size(device_path);
1015 return PMINFO_R_ERROR;
1017 *size = (int)total_size;
1022 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1026 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1028 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1029 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1031 locale = info->locale;
1032 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1034 for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
1035 if (ptr->lang == NULL)
1038 if (strcmp(ptr->lang, locale) == 0) {
1039 *icon = (char *)ptr->text;
1040 if (strcasecmp(*icon, "(null)") == 0) {
1041 locale = DEFAULT_LOCALE;
1046 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1047 *icon = (char *)ptr->text;
1052 return PMINFO_R_ERROR;
1055 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1059 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1062 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1064 locale = info->locale;
1065 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1067 for (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
1068 if (ptr->lang == NULL)
1071 if (strcmp(ptr->lang, locale) == 0) {
1072 *label = (char *)ptr->text;
1073 if (strcasecmp(*label, "(null)") == 0) {
1074 locale = DEFAULT_LOCALE;
1079 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1080 *label = (char *)ptr->text;
1085 return PMINFO_R_ERROR;
1088 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1092 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1095 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1097 locale = info->locale;
1098 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1100 for (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
1101 if (ptr->lang == NULL)
1104 if (strcmp(ptr->lang, locale) == 0) {
1105 *description = (char *)ptr->text;
1106 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
1107 locale = DEFAULT_LOCALE;
1112 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1113 *description = (char *)ptr->text;
1118 return PMINFO_R_ERROR;
1121 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1125 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1128 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1130 locale = info->locale;
1131 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1133 for (ptr = info->pkg_info->author; ptr != NULL; ptr = ptr->next) {
1134 if (ptr->lang == NULL)
1137 if (strcmp(ptr->lang, locale) == 0) {
1138 *author_name = (char *)ptr->text;
1139 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
1140 locale = DEFAULT_LOCALE;
1145 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1146 *author_name = (char *)ptr->text;
1151 return PMINFO_R_ERROR;
1154 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1156 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1158 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1159 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1161 if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
1162 info->pkg_info->author->email == NULL)
1163 return PMINFO_R_ERROR;
1165 *author_email = (char *)info->pkg_info->author->email;
1170 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1172 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1175 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1177 if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
1178 info->pkg_info->author->href == NULL)
1179 return PMINFO_R_ERROR;
1181 *author_href = (char *)info->pkg_info->author->href;
1186 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1188 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1190 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1191 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1193 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1194 return PMINFO_R_ERROR;
1196 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1197 *storage = PMINFO_INTERNAL_STORAGE;
1198 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1199 *storage = PMINFO_EXTERNAL_STORAGE;
1201 return PMINFO_R_ERROR;
1206 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1208 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1210 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1211 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1213 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1214 return PMINFO_R_ERROR;
1216 *installed_time = atoi(info->pkg_info->installed_time);
1221 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1223 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1225 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1226 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1228 if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
1229 return PMINFO_R_ERROR;
1231 *storeclientid = (char *)info->pkg_info->storeclient_id;
1236 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
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(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1243 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1244 return PMINFO_R_ERROR;
1246 *mainappid = (char *)info->pkg_info->mainapp_id;
1251 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1253 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1256 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1258 if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
1259 return PMINFO_R_ERROR;
1261 *url = (char *)info->pkg_info->package_url;
1266 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1268 const char *val = NULL;
1269 const xmlChar *node;
1270 xmlTextReaderPtr reader;
1271 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1272 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1275 reader = xmlReaderForFile(manifest, NULL, 0);
1278 if (__child_element(reader, -1)) {
1279 node = xmlTextReaderConstName(reader);
1281 _LOGE("xmlTextReaderConstName value is NULL\n");
1282 xmlFreeTextReader(reader);
1284 return PMINFO_R_ERROR;
1287 if (!strcmp(ASC_CHAR(node), "manifest")) {
1288 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1289 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1295 _LOGE("package size is not specified\n");
1296 xmlFreeTextReader(reader);
1298 return PMINFO_R_ERROR;
1301 _LOGE("Unable to create xml reader\n");
1302 xmlFreeTextReader(reader);
1304 return PMINFO_R_ERROR;
1308 _LOGE("xmlReaderForFile value is NULL\n");
1310 return PMINFO_R_ERROR;
1313 xmlFreeTextReader(reader);
1319 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1321 const char *val = NULL;
1322 const xmlChar *node;
1323 xmlTextReaderPtr reader;
1324 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1325 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1328 reader = xmlReaderForFile(manifest, NULL, 0);
1331 if ( __child_element(reader, -1)) {
1332 node = xmlTextReaderConstName(reader);
1334 _LOGE("xmlTextReaderConstName value is NULL\n");
1335 xmlFreeTextReader(reader);
1337 return PMINFO_R_ERROR;
1340 if (!strcmp(ASC_CHAR(node), "manifest")) {
1341 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1342 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1345 if (strcmp(val, "internal-only") == 0)
1346 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1347 else if (strcmp(val, "prefer-external") == 0)
1348 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1350 *location = PMINFO_INSTALL_LOCATION_AUTO;
1353 _LOGE("Unable to create xml reader\n");
1354 xmlFreeTextReader(reader);
1356 return PMINFO_R_ERROR;
1360 _LOGE("xmlReaderForFile value is NULL\n");
1362 return PMINFO_R_ERROR;
1365 xmlFreeTextReader(reader);
1372 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1374 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1376 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1377 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1379 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1380 return PMINFO_R_ERROR;
1382 *path = (char *)info->pkg_info->root_path;
1387 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1389 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1392 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1394 if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
1395 return PMINFO_R_ERROR;
1397 *path = (char *)info->pkg_info->csc_path;
1403 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1405 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1406 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1408 #if 0 //smack issue occured, check later
1410 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1412 _LOGD("invalid func parameters\n");
1413 return PMINFO_R_ERROR;
1415 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1418 char app_mmc_path[FILENAME_MAX] = { 0, };
1419 char app_dir_path[FILENAME_MAX] = { 0, };
1420 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1421 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1422 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1423 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1425 /*check whether application is in external memory or not */
1426 fp = fopen(app_mmc_path, "r");
1428 _LOGD(" app path in external memory not accesible\n");
1433 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1437 /*check whether application is in internal or not */
1438 fp = fopen(app_dir_path, "r");
1440 _LOGD(" app path in internal memory not accesible\n");
1442 return PMINFO_R_ERROR;
1445 /*check whether the application is installed in SD card
1446 but SD card is not present*/
1447 fp = fopen(app_mmc_internal_path, "r");
1450 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1455 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1460 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1467 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1470 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1473 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1475 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1476 return PMINFO_R_ERROR;
1478 val = (char *)info->pkg_info->removable;
1479 if (strcasecmp(val, "true") == 0)
1481 else if (strcasecmp(val, "false") == 0)
1489 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1492 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1495 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1497 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1498 return PMINFO_R_ERROR;
1500 val = (char *)info->pkg_info->installlocation;
1501 if (strcmp(val, "internal-only") == 0)
1503 else if (strcmp(val, "prefer-external") == 0)
1511 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1514 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1517 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1519 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1520 return PMINFO_R_ERROR;
1522 val = (char *)info->pkg_info->preload;
1523 if (strcasecmp(val, "true") == 0)
1525 else if (strcasecmp(val, "false") == 0)
1533 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1536 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1538 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1539 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1541 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1542 return PMINFO_R_ERROR;
1544 val = (char *)info->pkg_info->system;
1545 if (strcasecmp(val, "true") == 0)
1547 else if (strcasecmp(val, "false") == 0)
1555 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1558 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1560 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1561 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1563 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1564 return PMINFO_R_ERROR;
1566 val = (char *)info->pkg_info->readonly;
1567 if (strcasecmp(val, "true") == 0)
1569 else if (strcasecmp(val, "false") == 0)
1577 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1580 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1583 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1585 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1586 return PMINFO_R_ERROR;
1588 val = (char *)info->pkg_info->update;
1589 if (strcasecmp(val, "true") == 0)
1591 else if (strcasecmp(val, "false") == 0)
1599 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
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(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1607 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1608 return PMINFO_R_ERROR;
1610 val = (char *)info->pkg_info->for_all_users;
1611 if (strcasecmp(val, "1") == 0)
1613 else if (strcasecmp(val, "0") == 0)
1622 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1624 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1628 __cleanup_pkginfo(info);
1633 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1635 pkgmgrinfo_filter_x *filter;
1637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1639 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1640 if (filter == NULL) {
1641 _LOGE("Out of Memory!!!");
1642 return PMINFO_R_ERROR;
1650 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1652 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1654 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1657 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1658 g_slist_free(filter->list);
1666 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1667 const char *property, const int value)
1669 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1673 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1674 pkgmgrinfo_node_x *node;
1676 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1677 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1679 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1680 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1681 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1682 _LOGE("Invalid Integer Property\n");
1683 return PMINFO_R_EINVAL;
1685 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1687 _LOGE("Out of Memory!!!\n");
1688 return PMINFO_R_ERROR;
1690 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1691 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1693 _LOGE("Out of Memory\n");
1695 return PMINFO_R_ERROR;
1699 /*If API is called multiple times for same property, we should override the previous values.
1700 Last value set will be used for filtering.*/
1701 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1703 filter->list = g_slist_delete_link(filter->list, link);
1704 filter->list = g_slist_append(filter->list, (gpointer)node);
1709 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1710 const char *property, const bool value)
1715 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1716 pkgmgrinfo_node_x *node;
1718 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1719 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1721 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1722 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1723 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1724 _LOGE("Invalid Boolean Property\n");
1725 return PMINFO_R_EINVAL;
1727 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1729 _LOGE("Out of Memory!!!\n");
1730 return PMINFO_R_ERROR;
1733 val = strndup("('true','True')", 15);
1735 val = strndup("('false','False')", 17);
1737 _LOGE("Out of Memory\n");
1739 return PMINFO_R_ERROR;
1743 /*If API is called multiple times for same property, we should override the previous values.
1744 Last value set will be used for filtering.*/
1745 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1747 filter->list = g_slist_delete_link(filter->list, link);
1748 filter->list = g_slist_append(filter->list, (gpointer)node);
1753 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1754 const char *property, const char *value)
1759 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1760 pkgmgrinfo_node_x *node;
1762 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1763 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1764 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1766 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1767 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1768 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1769 _LOGE("Invalid String Property\n");
1770 return PMINFO_R_EINVAL;
1772 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1774 _LOGE("Out of Memory!!!\n");
1775 return PMINFO_R_ERROR;
1777 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1778 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1779 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1780 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1781 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1782 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1783 else if (strcmp(value, "installed_internal") == 0)
1784 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1785 else if (strcmp(value, "installed_external") == 0)
1786 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1788 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1790 _LOGE("Out of Memory\n");
1792 return PMINFO_R_ERROR;
1796 /*If API is called multiple times for same property, we should override the previous values.
1797 Last value set will be used for filtering.*/
1798 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1800 filter->list = g_slist_delete_link(filter->list, link);
1801 filter->list = g_slist_append(filter->list, (gpointer)node);
1806 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1809 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1810 char *locale = NULL;
1811 char *condition = NULL;
1812 char *error_message = NULL;
1813 char query[MAX_QUERY_LEN] = {'\0'};
1814 char where[MAX_QUERY_LEN] = {'\0'};
1818 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1820 /*Get current locale*/
1821 locale = _get_system_locale();
1822 if (locale == NULL) {
1823 _LOGE("manifest locale is NULL\n");
1824 return PMINFO_R_ERROR;
1827 ret = __open_manifest_db(uid);
1829 _LOGE("Fail to open manifest DB\n");
1831 return PMINFO_R_ERROR;
1834 /*Start constructing query*/
1835 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
1837 /*Get where clause*/
1838 for (list = filter->list; list; list = g_slist_next(list)) {
1839 __get_filter_condition(list->data, &condition);
1841 strncat(where, condition, sizeof(where) - strlen(where) -1);
1842 where[sizeof(where) - 1] = '\0';
1846 if (g_slist_next(list)) {
1847 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1848 where[sizeof(where) - 1] = '\0';
1851 if (strlen(where) > 0) {
1852 strncat(query, where, sizeof(query) - strlen(query) - 1);
1853 query[sizeof(query) - 1] = '\0';
1858 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1859 _LOGE("Don't execute query = %s error message = %s\n", query,
1861 sqlite3_free(error_message);
1862 ret = PMINFO_R_ERROR;
1872 __close_manifest_db();
1876 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1878 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
1881 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1882 pkgmgrinfo_pkginfo_filter_h handle,
1883 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1885 if (handle == NULL || pkg_cb == NULL) {
1886 LOGE("invalid parameter");
1887 return PMINFO_R_EINVAL;
1890 return _pkginfo_get_filtered_foreach_pkginfo(handle, pkg_cb, user_data,
1894 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1895 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1897 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
1900 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1901 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1903 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1904 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1906 privilege_x *ptr = NULL;
1907 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1908 ptr = info->pkg_info->privileges->privilege;
1909 for (; ptr; ptr = ptr->next) {
1911 ret = privilege_func(ptr->text, user_data);
1919 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
1921 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
1922 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1924 char *manifest = NULL;
1925 manifest_x *mfx = NULL;
1927 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
1928 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
1930 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1935 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
1937 *handle = (void *)mfx;
1942 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
1944 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
1945 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1947 char *manifest = NULL;
1948 manifest_x *mfx = NULL;
1950 manifest = pkgmgr_parser_get_manifest_file(pkgid);
1951 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
1953 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1958 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
1960 *handle = (void *)mfx;
1965 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
1968 manifest_x *mfx = (manifest_x *)handle;
1970 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
1971 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1974 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
1977 free((void *)mfx->type);
1979 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
1984 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
1987 manifest_x *mfx = (manifest_x *)handle;
1989 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
1990 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1992 len = strlen(version);
1993 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
1996 free((void *)mfx->version);
1998 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
2002 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
2004 manifest_x *mfx = (manifest_x *)handle;
2006 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2007 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2009 if (mfx->installlocation)
2010 free((void *)mfx->installlocation);
2012 if (location == INSTALL_INTERNAL)
2013 mfx->installlocation = strdup("internal-only");
2014 else if (location == INSTALL_EXTERNAL)
2015 mfx->installlocation = strdup("prefer-external");
2020 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
2022 manifest_x *mfx = (manifest_x *)handle;
2024 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2025 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
2027 if (mfx->package_size)
2028 free((void *)mfx->package_size);
2030 mfx->package_size = strdup(size);
2035 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
2038 manifest_x *mfx = (manifest_x *)handle;
2041 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2042 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2044 len = strlen(label_txt);
2045 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2047 label = calloc(1, sizeof(label_x));
2048 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2050 LISTADD(mfx->label, label);
2052 mfx->label->lang = strdup(locale);
2054 mfx->label->lang = strdup(DEFAULT_LOCALE);
2055 mfx->label->text = strdup(label_txt);
2060 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
2063 manifest_x *mfx = (manifest_x *)handle;
2066 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2067 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2069 len = strlen(icon_txt);
2070 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2072 icon = calloc(1, sizeof(icon_x));
2073 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2075 LISTADD(mfx->icon, icon);
2077 mfx->icon->lang = strdup(locale);
2079 mfx->icon->lang = strdup(DEFAULT_LOCALE);
2080 mfx->icon->text = strdup(icon_txt);
2085 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
2087 int len = strlen(desc_txt);
2088 manifest_x *mfx = (manifest_x *)handle;
2089 description_x *description;
2091 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2092 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2094 len = strlen(desc_txt);
2095 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2097 description = calloc(1, sizeof(description_x));
2098 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2100 LISTADD(mfx->description, description);
2102 mfx->description->lang = strdup(locale);
2104 mfx->description->lang = strdup(DEFAULT_LOCALE);
2105 mfx->description->text = strdup(desc_txt);
2110 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
2111 const char *author_email, const char *author_href, const char *locale)
2113 manifest_x *mfx = (manifest_x *)handle;
2116 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2118 author = calloc(1, sizeof(author_x));
2119 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
2121 LISTADD(mfx->author, author);
2123 mfx->author->text = strdup(author_name);
2125 mfx->author->email = strdup(author_email);
2127 mfx->author->href = strdup(author_href);
2129 mfx->author->lang = strdup(locale);
2131 mfx->author->lang = strdup(DEFAULT_LOCALE);
2135 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
2137 manifest_x *mfx = (manifest_x *)handle;
2139 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2140 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2143 free((void *)mfx->removable);
2146 mfx->removable = strdup("false");
2147 else if (removable == 1)
2148 mfx->removable = strdup("true");
2153 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
2155 manifest_x *mfx = (manifest_x *)handle;
2157 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2158 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2161 free((void *)mfx->preload);
2164 mfx->preload = strdup("false");
2165 else if (preload == 1)
2166 mfx->preload = strdup("true");
2171 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
2173 manifest_x *mfx = (manifest_x *)handle;
2175 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2176 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2178 if (mfx->installed_storage)
2179 free((void *)mfx->installed_storage);
2181 if (location == INSTALL_INTERNAL)
2182 mfx->installed_storage = strdup("installed_internal");
2183 else if (location == INSTALL_EXTERNAL)
2184 mfx->installed_storage = strdup("installed_external");
2189 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
2192 manifest_x *mfx = (manifest_x *)handle;
2193 mfx = (manifest_x *)handle;
2195 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2197 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2199 _LOGE("Successfully stored info in DB\n");
2202 _LOGE("Failed to store info in DB\n");
2203 return PMINFO_R_ERROR;
2207 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
2210 manifest_x *mfx = (manifest_x *)handle;
2212 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2214 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2216 _LOGE("Successfully stored info in DB\n");
2219 _LOGE("Failed to store info in DB\n");
2220 return PMINFO_R_ERROR;
2224 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
2226 manifest_x *mfx = (manifest_x *)handle;
2228 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2230 pkgmgrinfo_basic_free_package(mfx);