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 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
50 "from package_info LEFT OUTER JOIN package_localized_info " \
51 "ON package_info.package=package_localized_info.package " \
52 "and package_localized_info.package_locale='%s' where "
55 static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
56 pkgmgr_pkginfo_x **pkginfo);
57 static char *_get_filtered_query(const char *query_raw,
58 pkgmgrinfo_filter_x *filter);
60 static gint __compare_func(gconstpointer data1, gconstpointer data2)
62 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
63 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
64 if (node1->prop == node2->prop)
66 else if (node1->prop > node2->prop)
72 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
76 _LOGE("count value is %d\n", *p);
80 static void __destroy_each_node(gpointer data, gpointer user_data)
83 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
96 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
100 free((void *)data->locale);
104 pkgmgrinfo_basic_free_package(data->pkg_info);
110 static int __child_element(xmlTextReaderPtr reader, int depth)
112 int ret = xmlTextReaderRead(reader);
113 int cur = xmlTextReaderDepth(reader);
116 switch (xmlTextReaderNodeType(reader)) {
117 case XML_READER_TYPE_ELEMENT:
118 if (cur == depth + 1)
121 case XML_READER_TYPE_TEXT:
122 /*text is handled by each function separately*/
123 if (cur == depth + 1)
126 case XML_READER_TYPE_END_ELEMENT:
135 ret = xmlTextReaderRead(reader);
136 cur = xmlTextReaderDepth(reader);
141 long long _pkgmgr_calculate_dir_size(char *dirname)
145 int q = 0; /*quotient*/
146 int r = 0; /*remainder*/
148 struct dirent *ep = NULL;
149 struct stat fileinfo;
150 char abs_filename[FILENAME_MAX] = { 0, };
151 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
153 dp = opendir(dirname);
155 while ((ep = readdir(dp)) != NULL) {
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;
189 _LOGE("Couldn't open the directory\n");
196 static GSList *_pkginfo_get_filtered_list(const char *locale,
197 pkgmgrinfo_filter_x *filter)
199 static const char query_raw[] =
200 "SELECT DISTINCT package_info.package FROM package_info"
201 " LEFT OUTER JOIN package_localized_info"
202 " ON package_info.package=package_localized_info.package"
203 " AND package_localized_info.package_locale=%Q "
204 " LEFT OUTER JOIN package_privilege_info"
205 " ON package_info.package=package_privilege_info.package";
208 char *query_localized;
213 query = _get_filtered_query(query_raw, filter);
216 query_localized = sqlite3_mprintf(query, locale);
218 if (query_localized == NULL)
221 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
222 strlen(query_localized), &stmt, NULL);
223 sqlite3_free(query_localized);
224 if (ret != SQLITE_OK) {
225 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
229 while (sqlite3_step(stmt) == SQLITE_ROW) {
230 _save_column_str(stmt, 0, (const char **)&pkgid);
231 list = g_slist_append(list, pkgid);
234 sqlite3_finalize(stmt);
239 static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
240 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
242 pkgmgr_pkginfo_x *info;
249 if (__open_manifest_db(uid, true) < 0)
250 return PMINFO_R_ERROR;
252 locale = _get_system_locale();
253 if (locale == NULL) {
254 __close_manifest_db();
255 return PMINFO_R_ERROR;
258 list = _pkginfo_get_filtered_list(locale, filter);
261 __close_manifest_db();
265 for (tmp = list; tmp; tmp = tmp->next) {
266 pkgid = (char *)tmp->data;
268 if (_pkginfo_get_pkg(pkgid, locale, &info)) {
273 if (pkg_list_cb(info, user_data) < 0)
275 pkgmgrinfo_pkginfo_destroy_pkginfo(info);
282 __close_manifest_db();
287 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
288 void *user_data, uid_t uid)
290 if (pkg_list_cb == NULL) {
291 LOGE("invalid parameter");
292 return PMINFO_R_EINVAL;
295 return _pkginfo_get_filtered_foreach_pkginfo(NULL, pkg_list_cb,
299 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
301 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
304 static int _pkginfo_get_author(const char *pkgid, author_x **author)
306 static const char query_raw[] =
307 "SELECT author_name, author_email, author_href "
308 "FROM package_info WHERE package=%Q";
315 query = sqlite3_mprintf(query_raw, pkgid);
317 LOGE("out of memory");
318 return PMINFO_R_ERROR;
321 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
324 if (ret != SQLITE_OK) {
325 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
326 return PMINFO_R_ERROR;
329 if (sqlite3_step(stmt) == SQLITE_ERROR) {
330 LOGE("step error: %s", sqlite3_errmsg(GET_DB(manifest_db)));
331 sqlite3_finalize(stmt);
332 return PMINFO_R_ERROR;
335 /* one author per one package */
336 info = calloc(1, sizeof(author_x));
338 LOGE("out of memory");
339 sqlite3_finalize(stmt);
340 return PMINFO_R_ERROR;
343 _save_column_str(stmt, idx++, &info->text);
344 _save_column_str(stmt, idx++, &info->email);
345 _save_column_str(stmt, idx++, &info->href);
349 sqlite3_finalize(stmt);
354 static int _pkginfo_get_label(const char *pkgid, const char *locale,
357 static const char query_raw[] =
358 "SELECT package_label, package_locale "
359 "FROM package_localized_info "
360 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
367 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
369 LOGE("out of memory");
370 return PMINFO_R_ERROR;
373 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
376 if (ret != SQLITE_OK) {
377 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
378 return PMINFO_R_ERROR;
381 while (sqlite3_step(stmt) == SQLITE_ROW) {
382 info = calloc(1, sizeof(label_x));
384 LOGE("out of memory");
385 sqlite3_finalize(stmt);
387 LISTHEAD(*label, info);
390 return PMINFO_R_ERROR;
393 _save_column_str(stmt, idx++, &info->text);
394 _save_column_str(stmt, idx++, &info->lang);
395 LISTADD(*label, info);
399 LISTHEAD(*label, info);
403 sqlite3_finalize(stmt);
408 static int _pkginfo_get_icon(const char *pkgid, const char *locale,
411 static const char query_raw[] =
412 "SELECT package_icon, package_locale "
413 "FROM package_localized_info "
414 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
421 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
423 LOGE("out of memory");
424 return PMINFO_R_ERROR;
427 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
430 if (ret != SQLITE_OK) {
431 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
432 return PMINFO_R_ERROR;
435 while (sqlite3_step(stmt) == SQLITE_ROW) {
436 info = calloc(1, sizeof(icon_x));
438 LOGE("out of memory");
439 sqlite3_finalize(stmt);
441 LISTHEAD(*icon, info);
444 return PMINFO_R_ERROR;
447 _save_column_str(stmt, idx++, &info->text);
448 _save_column_str(stmt, idx++, &info->lang);
449 LISTADD(*icon, info);
453 LISTHEAD(*icon, info);
457 sqlite3_finalize(stmt);
462 static int _pkginfo_get_description(const char *pkgid, const char *locale,
463 description_x **description)
465 static const char query_raw[] =
466 "SELECT package_description, package_locale "
467 "FROM package_localized_info "
468 "WHERE package=%Q AND package_locale IN (%Q, %Q)";
475 query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
477 LOGE("out of memory");
478 return PMINFO_R_ERROR;
481 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
484 if (ret != SQLITE_OK) {
485 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
486 return PMINFO_R_ERROR;
489 while (sqlite3_step(stmt) == SQLITE_ROW) {
490 info = calloc(1, sizeof(description_x));
492 LOGE("out of memory");
493 sqlite3_finalize(stmt);
495 LISTHEAD(*description, info);
498 return PMINFO_R_ERROR;
501 _save_column_str(stmt, idx++, &info->text);
502 _save_column_str(stmt, idx++, &info->lang);
503 LISTADD(*description, info);
507 LISTHEAD(*description, info);
511 sqlite3_finalize(stmt);
516 static int _pkginfo_get_privilege(const char *pkgid, privileges_x **privileges)
518 static const char query_raw[] =
519 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
526 /* privilege list should stored in privileges_x... */
527 p = calloc(1, sizeof(privileges_x));
529 LOGE("out of memory");
530 return PMINFO_R_ERROR;
534 query = sqlite3_mprintf(query_raw, pkgid);
536 LOGE("out of memory");
538 return PMINFO_R_ERROR;
541 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
544 if (ret != SQLITE_OK) {
545 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
547 return PMINFO_R_ERROR;
550 while (sqlite3_step(stmt) == SQLITE_ROW) {
551 info = calloc(1, sizeof(privilege_x));
553 LOGE("out of memory");
554 sqlite3_finalize(stmt);
556 LISTHEAD(p->privilege, info);
559 return PMINFO_R_ERROR;
561 _save_column_str(stmt, 0, &info->text);
562 LISTADD(p->privilege, info);
566 LISTHEAD(p->privilege, info);
570 sqlite3_finalize(stmt);
575 static char *_get_filtered_query(const char *query_raw,
576 pkgmgrinfo_filter_x *filter)
578 char buf[MAX_QUERY_LEN] = { 0, };
587 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
589 for (list = head; list; list = list->next) {
590 /* TODO: revise condition getter function */
591 __get_filter_condition(list->data, &condition);
592 if (condition == NULL)
594 if (buf[strlen(query_raw)] == '\0') {
595 len += strlen(" WHERE ");
596 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
598 len += strlen(" AND ");
599 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
601 len += strlen(condition);
602 strncat(buf, condition, sizeof(buf) - len - 1);
610 static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
611 pkgmgr_pkginfo_x **pkginfo)
613 static const char query_raw[] =
614 "SELECT for_all_users, package, package_version, "
615 "install_location, package_removable, package_preload, "
616 "package_readonly, package_update, package_appsetting, "
617 "package_system, package_type, package_size, installed_time, "
618 "installed_storage, storeclient_id, mainapp_id, package_url, "
619 "root_path, csc_path, package_nodisplay, package_api_version "
620 "FROM package_info WHERE package=%Q order by for_all_users";
625 pkgmgr_pkginfo_x *info;
628 query = sqlite3_mprintf(query_raw, pkgid);
630 LOGE("out of memory");
631 return PMINFO_R_ERROR;
634 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
637 if (ret != SQLITE_OK) {
638 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
639 return PMINFO_R_ERROR;
642 ret = sqlite3_step(stmt);
643 if (ret == SQLITE_DONE) {
644 LOGE("cannot find pkg");
645 sqlite3_finalize(stmt);
646 return PMINFO_R_ENOENT;
647 } else if (ret != SQLITE_ROW) {
648 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
649 sqlite3_finalize(stmt);
650 return PMINFO_R_ERROR;
653 pkg = calloc(1, sizeof(package_x));
655 LOGE("out of memory");
656 sqlite3_finalize(stmt);
657 return PMINFO_R_ERROR;
660 _save_column_str(stmt, idx++, &pkg->for_all_users);
661 _save_column_str(stmt, idx++, &pkg->package);
662 _save_column_str(stmt, idx++, &pkg->version);
663 _save_column_str(stmt, idx++, &pkg->installlocation);
664 _save_column_str(stmt, idx++, &pkg->removable);
665 _save_column_str(stmt, idx++, &pkg->preload);
666 _save_column_str(stmt, idx++, &pkg->readonly);
667 _save_column_str(stmt, idx++, &pkg->update);
668 _save_column_str(stmt, idx++, &pkg->appsetting);
669 _save_column_str(stmt, idx++, &pkg->system);
670 _save_column_str(stmt, idx++, &pkg->type);
671 _save_column_str(stmt, idx++, &pkg->package_size);
672 _save_column_str(stmt, idx++, &pkg->installed_time);
673 _save_column_str(stmt, idx++, &pkg->installed_storage);
674 _save_column_str(stmt, idx++, &pkg->storeclient_id);
675 _save_column_str(stmt, idx++, &pkg->mainapp_id);
676 _save_column_str(stmt, idx++, &pkg->package_url);
677 _save_column_str(stmt, idx++, &pkg->root_path);
678 _save_column_str(stmt, idx++, &pkg->csc_path);
679 _save_column_str(stmt, idx++, &pkg->nodisplay_setting);
680 _save_column_str(stmt, idx++, &pkg->api_version);
682 if (_pkginfo_get_author(pkg->package, &pkg->author)) {
683 pkgmgrinfo_basic_free_package(pkg);
684 sqlite3_finalize(stmt);
685 return PMINFO_R_ERROR;
688 if (_pkginfo_get_label(pkg->package, locale, &pkg->label)) {
689 pkgmgrinfo_basic_free_package(pkg);
690 sqlite3_finalize(stmt);
691 return PMINFO_R_ERROR;
694 if (_pkginfo_get_icon(pkg->package, locale, &pkg->icon)) {
695 pkgmgrinfo_basic_free_package(pkg);
696 sqlite3_finalize(stmt);
697 return PMINFO_R_ERROR;
700 if (_pkginfo_get_description(pkg->package, locale,
701 &pkg->description)) {
702 pkgmgrinfo_basic_free_package(pkg);
703 sqlite3_finalize(stmt);
704 return PMINFO_R_ERROR;
707 if (_pkginfo_get_privilege(pkg->package, &pkg->privileges)) {
708 pkgmgrinfo_basic_free_package(pkg);
709 sqlite3_finalize(stmt);
710 return PMINFO_R_ERROR;
713 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
715 LOGE("out of memory");
716 pkgmgrinfo_basic_free_package(pkg);
717 sqlite3_finalize(stmt);
718 return PMINFO_R_ERROR;
721 info->pkg_info = pkg;
722 info->locale = strdup(locale);
725 sqlite3_finalize(stmt);
730 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
731 pkgmgrinfo_pkginfo_h *handle)
733 pkgmgr_pkginfo_x *pkginfo = NULL;
736 if (pkgid == NULL || handle == NULL) {
737 LOGE("invalid parameter");
738 return PMINFO_R_EINVAL;
741 if (__open_manifest_db(uid, true) < 0)
742 return PMINFO_R_ERROR;
745 locale = _get_system_locale();
746 if (locale == NULL) {
747 __close_manifest_db();
748 return PMINFO_R_ERROR;
751 if (_pkginfo_get_pkg(pkgid, locale, &pkginfo)) {
752 LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
754 __close_manifest_db();
755 return PMINFO_R_ERROR;
762 __close_manifest_db();
767 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
769 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
772 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
774 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
776 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
777 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
779 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
780 return PMINFO_R_ERROR;
782 *pkg_name = (char *)info->pkg_info->package;
787 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
789 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
791 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
792 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
794 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
795 return PMINFO_R_ERROR;
797 *pkgid = (char *)info->pkg_info->package;
802 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
804 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
806 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
807 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
809 if (info->pkg_info == NULL || info->pkg_info->type == NULL)
810 return PMINFO_R_ERROR;
812 *type = (char *)info->pkg_info->type;
817 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
819 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
822 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
824 if (info->pkg_info == NULL || info->pkg_info->version == NULL)
825 return PMINFO_R_ERROR;
827 *version = (char *)info->pkg_info->version;
832 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
835 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
837 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
838 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
840 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
841 return PMINFO_R_ERROR;
843 val = (char *)info->pkg_info->installlocation;
844 if (strcmp(val, "internal-only") == 0)
845 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
846 else if (strcmp(val, "prefer-external") == 0)
847 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
849 *location = PMINFO_INSTALL_LOCATION_AUTO;
854 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
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(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
861 if (info->pkg_info == NULL || info->pkg_info->package_size == NULL)
862 return PMINFO_R_ERROR;
864 *size = atoi((char *)info->pkg_info->package_size);
869 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
872 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
873 long long rw_size = 0;
874 long long ro_size = 0;
875 long long tmp_size = 0;
876 long long total_size = 0;
877 struct stat fileinfo;
880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
881 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
883 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
885 return PMINFO_R_ERROR;
888 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
889 if (lstat(device_path, &fileinfo) == 0) {
890 if (!S_ISLNK(fileinfo.st_mode)) {
891 tmp_size = _pkgmgr_calculate_dir_size(device_path);
897 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
898 if (lstat(device_path, &fileinfo) == 0) {
899 if (!S_ISLNK(fileinfo.st_mode)) {
900 tmp_size = _pkgmgr_calculate_dir_size(device_path);
906 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
907 if (lstat(device_path, &fileinfo) == 0) {
908 if (!S_ISLNK(fileinfo.st_mode)) {
909 tmp_size = _pkgmgr_calculate_dir_size(device_path);
915 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
916 if (lstat(device_path, &fileinfo) == 0) {
917 if (!S_ISLNK(fileinfo.st_mode)) {
918 tmp_size = _pkgmgr_calculate_dir_size(device_path);
924 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
925 if (lstat(device_path, &fileinfo) == 0) {
926 if (!S_ISLNK(fileinfo.st_mode)) {
927 tmp_size = _pkgmgr_calculate_dir_size(device_path);
933 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
934 if (lstat(device_path, &fileinfo) == 0) {
935 if (!S_ISLNK(fileinfo.st_mode)) {
936 tmp_size = _pkgmgr_calculate_dir_size(device_path);
943 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
944 if (lstat(device_path, &fileinfo) == 0) {
945 if (!S_ISLNK(fileinfo.st_mode)) {
946 tmp_size = _pkgmgr_calculate_dir_size(device_path);
952 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
953 if (lstat(device_path, &fileinfo) == 0) {
954 if (!S_ISLNK(fileinfo.st_mode)) {
955 tmp_size = _pkgmgr_calculate_dir_size(device_path);
961 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
962 if (lstat(device_path, &fileinfo) == 0) {
963 if (!S_ISLNK(fileinfo.st_mode)) {
964 tmp_size = _pkgmgr_calculate_dir_size(device_path);
970 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
971 if (lstat(device_path, &fileinfo) == 0) {
972 if (!S_ISLNK(fileinfo.st_mode)) {
973 tmp_size = _pkgmgr_calculate_dir_size(device_path);
979 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
980 if (lstat(device_path, &fileinfo) == 0) {
981 if (!S_ISLNK(fileinfo.st_mode)) {
982 tmp_size = _pkgmgr_calculate_dir_size(device_path);
988 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
989 if (lstat(device_path, &fileinfo) == 0) {
990 if (!S_ISLNK(fileinfo.st_mode)) {
991 tmp_size = _pkgmgr_calculate_dir_size(device_path);
998 total_size = rw_size + ro_size;
999 *size = (int)total_size;
1004 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
1007 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
1008 long long total_size = 0;
1010 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1011 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1013 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
1014 return PMINFO_R_ERROR;
1016 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
1017 if (access(device_path, R_OK) == 0)
1018 total_size = _pkgmgr_calculate_dir_size(device_path);
1020 return PMINFO_R_ERROR;
1022 *size = (int)total_size;
1027 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1031 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1033 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1034 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1036 locale = info->locale;
1037 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1039 for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
1040 if (ptr->lang == NULL)
1043 if (strcmp(ptr->lang, locale) == 0) {
1044 *icon = (char *)ptr->text;
1045 if (strcasecmp(*icon, "(null)") == 0) {
1046 locale = DEFAULT_LOCALE;
1051 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1052 *icon = (char *)ptr->text;
1057 return PMINFO_R_ERROR;
1060 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1064 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1067 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1069 locale = info->locale;
1070 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1072 for (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
1073 if (ptr->lang == NULL)
1076 if (strcmp(ptr->lang, locale) == 0) {
1077 *label = (char *)ptr->text;
1078 if (strcasecmp(*label, "(null)") == 0) {
1079 locale = DEFAULT_LOCALE;
1084 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1085 *label = (char *)ptr->text;
1090 return PMINFO_R_ERROR;
1093 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1097 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1099 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1100 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1102 locale = info->locale;
1103 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1105 for (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
1106 if (ptr->lang == NULL)
1109 if (strcmp(ptr->lang, locale) == 0) {
1110 *description = (char *)ptr->text;
1111 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
1112 locale = DEFAULT_LOCALE;
1117 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1118 *description = (char *)ptr->text;
1123 return PMINFO_R_ERROR;
1126 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1130 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1132 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1133 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1135 locale = info->locale;
1136 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1138 for (ptr = info->pkg_info->author; ptr != NULL; ptr = ptr->next) {
1139 if (ptr->lang == NULL)
1142 if (strcmp(ptr->lang, locale) == 0) {
1143 *author_name = (char *)ptr->text;
1144 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
1145 locale = DEFAULT_LOCALE;
1150 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1151 *author_name = (char *)ptr->text;
1156 return PMINFO_R_ERROR;
1159 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1161 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1163 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1164 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1166 if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
1167 info->pkg_info->author->email == NULL)
1168 return PMINFO_R_ERROR;
1170 *author_email = (char *)info->pkg_info->author->email;
1175 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1177 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1180 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1182 if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
1183 info->pkg_info->author->href == NULL)
1184 return PMINFO_R_ERROR;
1186 *author_href = (char *)info->pkg_info->author->href;
1191 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1193 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1195 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1196 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1198 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1199 return PMINFO_R_ERROR;
1201 if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
1202 *storage = PMINFO_INTERNAL_STORAGE;
1203 else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
1204 *storage = PMINFO_EXTERNAL_STORAGE;
1206 return PMINFO_R_ERROR;
1211 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1213 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1215 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1216 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1218 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1219 return PMINFO_R_ERROR;
1221 *installed_time = atoi(info->pkg_info->installed_time);
1226 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1228 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1230 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1231 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1233 if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL)
1234 return PMINFO_R_ERROR;
1236 *storeclientid = (char *)info->pkg_info->storeclient_id;
1241 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1243 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1245 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1246 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1248 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1249 return PMINFO_R_ERROR;
1251 *mainappid = (char *)info->pkg_info->mainapp_id;
1256 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1258 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1261 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1263 if (info->pkg_info == NULL || info->pkg_info->package_url == NULL)
1264 return PMINFO_R_ERROR;
1266 *url = (char *)info->pkg_info->package_url;
1271 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
1273 const char *val = NULL;
1274 const xmlChar *node;
1275 xmlTextReaderPtr reader;
1276 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1277 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1280 reader = xmlReaderForFile(manifest, NULL, 0);
1283 if (__child_element(reader, -1)) {
1284 node = xmlTextReaderConstName(reader);
1286 _LOGE("xmlTextReaderConstName value is NULL\n");
1287 xmlFreeTextReader(reader);
1289 return PMINFO_R_ERROR;
1292 if (!strcmp(ASC_CHAR(node), "manifest")) {
1293 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
1294 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
1300 _LOGE("package size is not specified\n");
1301 xmlFreeTextReader(reader);
1303 return PMINFO_R_ERROR;
1306 _LOGE("Unable to create xml reader\n");
1307 xmlFreeTextReader(reader);
1309 return PMINFO_R_ERROR;
1313 _LOGE("xmlReaderForFile value is NULL\n");
1315 return PMINFO_R_ERROR;
1318 xmlFreeTextReader(reader);
1324 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
1326 const char *val = NULL;
1327 const xmlChar *node;
1328 xmlTextReaderPtr reader;
1329 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
1330 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1333 reader = xmlReaderForFile(manifest, NULL, 0);
1336 if ( __child_element(reader, -1)) {
1337 node = xmlTextReaderConstName(reader);
1339 _LOGE("xmlTextReaderConstName value is NULL\n");
1340 xmlFreeTextReader(reader);
1342 return PMINFO_R_ERROR;
1345 if (!strcmp(ASC_CHAR(node), "manifest")) {
1346 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
1347 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
1350 if (strcmp(val, "internal-only") == 0)
1351 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1352 else if (strcmp(val, "prefer-external") == 0)
1353 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1355 *location = PMINFO_INSTALL_LOCATION_AUTO;
1358 _LOGE("Unable to create xml reader\n");
1359 xmlFreeTextReader(reader);
1361 return PMINFO_R_ERROR;
1365 _LOGE("xmlReaderForFile value is NULL\n");
1367 return PMINFO_R_ERROR;
1370 xmlFreeTextReader(reader);
1377 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1379 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1382 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1384 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1385 return PMINFO_R_ERROR;
1387 *path = (char *)info->pkg_info->root_path;
1392 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1394 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1397 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1399 if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
1400 return PMINFO_R_ERROR;
1402 *path = (char *)info->pkg_info->csc_path;
1408 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1410 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1411 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1413 #if 0 //smack issue occured, check later
1415 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1417 _LOGD("invalid func parameters\n");
1418 return PMINFO_R_ERROR;
1420 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1423 char app_mmc_path[FILENAME_MAX] = { 0, };
1424 char app_dir_path[FILENAME_MAX] = { 0, };
1425 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1426 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
1427 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
1428 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1430 /*check whether application is in external memory or not */
1431 fp = fopen(app_mmc_path, "r");
1433 _LOGD(" app path in external memory not accesible\n");
1438 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1442 /*check whether application is in internal or not */
1443 fp = fopen(app_dir_path, "r");
1445 _LOGD(" app path in internal memory not accesible\n");
1447 return PMINFO_R_ERROR;
1450 /*check whether the application is installed in SD card
1451 but SD card is not present*/
1452 fp = fopen(app_mmc_internal_path, "r");
1455 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1460 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1465 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1472 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1475 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1477 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1478 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1480 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1481 return PMINFO_R_ERROR;
1483 val = (char *)info->pkg_info->removable;
1484 if (strcasecmp(val, "true") == 0)
1486 else if (strcasecmp(val, "false") == 0)
1494 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1497 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1499 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1500 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1502 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1503 return PMINFO_R_ERROR;
1505 val = (char *)info->pkg_info->installlocation;
1506 if (strcmp(val, "internal-only") == 0)
1508 else if (strcmp(val, "prefer-external") == 0)
1516 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1519 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1521 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1522 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1524 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1525 return PMINFO_R_ERROR;
1527 val = (char *)info->pkg_info->preload;
1528 if (strcasecmp(val, "true") == 0)
1530 else if (strcasecmp(val, "false") == 0)
1538 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1541 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1544 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1546 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1547 return PMINFO_R_ERROR;
1549 val = (char *)info->pkg_info->system;
1550 if (strcasecmp(val, "true") == 0)
1552 else if (strcasecmp(val, "false") == 0)
1560 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1563 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1566 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1568 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1569 return PMINFO_R_ERROR;
1571 val = (char *)info->pkg_info->readonly;
1572 if (strcasecmp(val, "true") == 0)
1574 else if (strcasecmp(val, "false") == 0)
1582 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1585 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1587 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1588 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1590 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1591 return PMINFO_R_ERROR;
1593 val = (char *)info->pkg_info->update;
1594 if (strcasecmp(val, "true") == 0)
1596 else if (strcasecmp(val, "false") == 0)
1604 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1607 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1610 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1612 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1613 return PMINFO_R_ERROR;
1615 val = (char *)info->pkg_info->for_all_users;
1616 if (strcasecmp(val, "1") == 0)
1618 else if (strcasecmp(val, "0") == 0)
1627 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1629 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1631 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1633 __cleanup_pkginfo(info);
1638 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1640 pkgmgrinfo_filter_x *filter;
1642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1644 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1645 if (filter == NULL) {
1646 _LOGE("Out of Memory!!!");
1647 return PMINFO_R_ERROR;
1655 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1657 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1662 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1663 g_slist_free(filter->list);
1671 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1672 const char *property, const int value)
1674 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1678 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1679 pkgmgrinfo_node_x *node;
1681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1682 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1684 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1685 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1686 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1687 _LOGE("Invalid Integer Property\n");
1688 return PMINFO_R_EINVAL;
1690 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1692 _LOGE("Out of Memory!!!\n");
1693 return PMINFO_R_ERROR;
1695 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1696 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1698 _LOGE("Out of Memory\n");
1700 return PMINFO_R_ERROR;
1704 /*If API is called multiple times for same property, we should override the previous values.
1705 Last value set will be used for filtering.*/
1706 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1708 filter->list = g_slist_delete_link(filter->list, link);
1709 filter->list = g_slist_append(filter->list, (gpointer)node);
1714 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1715 const char *property, const bool value)
1720 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1721 pkgmgrinfo_node_x *node;
1723 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1724 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1726 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1727 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1728 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1729 _LOGE("Invalid Boolean Property\n");
1730 return PMINFO_R_EINVAL;
1732 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1734 _LOGE("Out of Memory!!!\n");
1735 return PMINFO_R_ERROR;
1738 val = strndup("('true','True')", 15);
1740 val = strndup("('false','False')", 17);
1742 _LOGE("Out of Memory\n");
1744 return PMINFO_R_ERROR;
1748 /*If API is called multiple times for same property, we should override the previous values.
1749 Last value set will be used for filtering.*/
1750 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1752 filter->list = g_slist_delete_link(filter->list, link);
1753 filter->list = g_slist_append(filter->list, (gpointer)node);
1758 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1759 const char *property, const char *value)
1764 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1765 pkgmgrinfo_node_x *node;
1767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1768 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1769 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1771 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1772 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1773 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1774 _LOGE("Invalid String Property\n");
1775 return PMINFO_R_EINVAL;
1777 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1779 _LOGE("Out of Memory!!!\n");
1780 return PMINFO_R_ERROR;
1782 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1783 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1784 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1785 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1786 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1787 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1788 else if (strcmp(value, "installed_internal") == 0)
1789 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1790 else if (strcmp(value, "installed_external") == 0)
1791 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1793 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1795 _LOGE("Out of Memory\n");
1797 return PMINFO_R_ERROR;
1801 /*If API is called multiple times for same property, we should override the previous values.
1802 Last value set will be used for filtering.*/
1803 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1805 filter->list = g_slist_delete_link(filter->list, link);
1806 filter->list = g_slist_append(filter->list, (gpointer)node);
1811 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1814 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1815 char *locale = NULL;
1816 char *condition = NULL;
1817 char *error_message = NULL;
1818 char query[MAX_QUERY_LEN] = {'\0'};
1819 char where[MAX_QUERY_LEN] = {'\0'};
1823 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1825 /*Get current locale*/
1826 locale = _get_system_locale();
1827 if (locale == NULL) {
1828 _LOGE("manifest locale is NULL\n");
1829 return PMINFO_R_ERROR;
1832 ret = __open_manifest_db(uid, true);
1834 _LOGE("Fail to open manifest DB\n");
1836 return PMINFO_R_ERROR;
1839 /*Start constructing query*/
1840 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
1842 /*Get where clause*/
1843 for (list = filter->list; list; list = g_slist_next(list)) {
1844 __get_filter_condition(list->data, &condition);
1846 strncat(where, condition, sizeof(where) - strlen(where) -1);
1847 where[sizeof(where) - 1] = '\0';
1851 if (g_slist_next(list)) {
1852 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1853 where[sizeof(where) - 1] = '\0';
1856 if (strlen(where) > 0) {
1857 strncat(query, where, sizeof(query) - strlen(query) - 1);
1858 query[sizeof(query) - 1] = '\0';
1863 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1864 _LOGE("Don't execute query = %s error message = %s\n", query,
1866 sqlite3_free(error_message);
1867 ret = PMINFO_R_ERROR;
1877 __close_manifest_db();
1881 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1883 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
1886 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1887 pkgmgrinfo_pkginfo_filter_h handle,
1888 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1890 if (handle == NULL || pkg_cb == NULL) {
1891 LOGE("invalid parameter");
1892 return PMINFO_R_EINVAL;
1895 return _pkginfo_get_filtered_foreach_pkginfo(handle, pkg_cb, user_data,
1899 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1900 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1902 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
1905 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1906 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1908 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1909 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1911 privilege_x *ptr = NULL;
1912 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1913 ptr = info->pkg_info->privileges->privilege;
1914 for (; ptr; ptr = ptr->next) {
1916 ret = privilege_func(ptr->text, user_data);
1924 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
1926 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
1927 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1929 char *manifest = NULL;
1930 manifest_x *mfx = NULL;
1932 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
1933 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
1935 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1940 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
1942 *handle = (void *)mfx;
1947 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
1949 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
1950 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1952 char *manifest = NULL;
1953 manifest_x *mfx = NULL;
1955 manifest = pkgmgr_parser_get_manifest_file(pkgid);
1956 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
1958 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1963 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
1965 *handle = (void *)mfx;
1970 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
1973 manifest_x *mfx = (manifest_x *)handle;
1975 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
1976 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1979 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
1982 free((void *)mfx->type);
1984 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
1989 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
1992 manifest_x *mfx = (manifest_x *)handle;
1994 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
1995 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
1997 len = strlen(version);
1998 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2001 free((void *)mfx->version);
2003 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
2007 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
2009 manifest_x *mfx = (manifest_x *)handle;
2011 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2012 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2014 if (mfx->installlocation)
2015 free((void *)mfx->installlocation);
2017 if (location == INSTALL_INTERNAL)
2018 mfx->installlocation = strdup("internal-only");
2019 else if (location == INSTALL_EXTERNAL)
2020 mfx->installlocation = strdup("prefer-external");
2025 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
2027 manifest_x *mfx = (manifest_x *)handle;
2029 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2030 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
2032 if (mfx->package_size)
2033 free((void *)mfx->package_size);
2035 mfx->package_size = strdup(size);
2040 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
2043 manifest_x *mfx = (manifest_x *)handle;
2046 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2047 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2049 len = strlen(label_txt);
2050 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2052 label = calloc(1, sizeof(label_x));
2053 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2055 LISTADD(mfx->label, label);
2057 mfx->label->lang = strdup(locale);
2059 mfx->label->lang = strdup(DEFAULT_LOCALE);
2060 mfx->label->text = strdup(label_txt);
2065 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
2068 manifest_x *mfx = (manifest_x *)handle;
2071 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2072 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2074 len = strlen(icon_txt);
2075 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2077 icon = calloc(1, sizeof(icon_x));
2078 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2080 LISTADD(mfx->icon, icon);
2082 mfx->icon->lang = strdup(locale);
2084 mfx->icon->lang = strdup(DEFAULT_LOCALE);
2085 mfx->icon->text = strdup(icon_txt);
2090 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
2092 int len = strlen(desc_txt);
2093 manifest_x *mfx = (manifest_x *)handle;
2094 description_x *description;
2096 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2097 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
2099 len = strlen(desc_txt);
2100 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
2102 description = calloc(1, sizeof(description_x));
2103 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
2105 LISTADD(mfx->description, description);
2107 mfx->description->lang = strdup(locale);
2109 mfx->description->lang = strdup(DEFAULT_LOCALE);
2110 mfx->description->text = strdup(desc_txt);
2115 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
2116 const char *author_email, const char *author_href, const char *locale)
2118 manifest_x *mfx = (manifest_x *)handle;
2121 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2123 author = calloc(1, sizeof(author_x));
2124 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
2126 LISTADD(mfx->author, author);
2128 mfx->author->text = strdup(author_name);
2130 mfx->author->email = strdup(author_email);
2132 mfx->author->href = strdup(author_href);
2134 mfx->author->lang = strdup(locale);
2136 mfx->author->lang = strdup(DEFAULT_LOCALE);
2140 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
2142 manifest_x *mfx = (manifest_x *)handle;
2144 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2145 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2148 free((void *)mfx->removable);
2151 mfx->removable = strdup("false");
2152 else if (removable == 1)
2153 mfx->removable = strdup("true");
2158 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
2160 manifest_x *mfx = (manifest_x *)handle;
2162 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2163 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2166 free((void *)mfx->preload);
2169 mfx->preload = strdup("false");
2170 else if (preload == 1)
2171 mfx->preload = strdup("true");
2176 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
2178 manifest_x *mfx = (manifest_x *)handle;
2180 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2181 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
2183 if (mfx->installed_storage)
2184 free((void *)mfx->installed_storage);
2186 if (location == INSTALL_INTERNAL)
2187 mfx->installed_storage = strdup("installed_internal");
2188 else if (location == INSTALL_EXTERNAL)
2189 mfx->installed_storage = strdup("installed_external");
2194 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
2197 manifest_x *mfx = (manifest_x *)handle;
2198 mfx = (manifest_x *)handle;
2200 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2202 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2204 _LOGE("Successfully stored info in DB\n");
2207 _LOGE("Failed to store info in DB\n");
2208 return PMINFO_R_ERROR;
2212 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
2215 manifest_x *mfx = (manifest_x *)handle;
2217 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2219 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2221 _LOGE("Successfully stored info in DB\n");
2224 _LOGE("Failed to store info in DB\n");
2225 return PMINFO_R_ERROR;
2229 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
2231 manifest_x *mfx = (manifest_x *)handle;
2233 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
2235 pkgmgrinfo_basic_free_package(mfx);