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>
38 #include "pkgmgrinfo_basic.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
43 static bool _get_bool_value(const char *str)
45 if (str && !strcmp(str, "true"))
51 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
54 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
55 if (node1->prop == node2->prop)
57 else if (node1->prop > node2->prop)
63 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
65 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
67 if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
73 static void __destroy_each_node(gpointer data, gpointer user_data)
76 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
89 static void __destroy_metadata_node(gpointer data)
91 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
99 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
101 ret_if(data == NULL);
103 free((void *)data->locale);
107 pkgmgrinfo_basic_free_package(data->pkg_info);
113 long long _pkgmgr_calculate_dir_size(char *dirname)
117 int q = 0; /*quotient*/
118 int r = 0; /*remainder*/
121 struct stat fileinfo;
122 char abs_filename[FILENAME_MAX] = { 0, };
123 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
125 dp = opendir(dirname);
127 _LOGE("Couldn't open the directory\n");
131 for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) {
132 if (!strcmp(ep->d_name, ".") ||
133 !strcmp(ep->d_name, "..")) {
136 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
138 if (lstat(abs_filename, &fileinfo) < 0)
139 perror(abs_filename);
141 if (S_ISDIR(fileinfo.st_mode)) {
142 total += fileinfo.st_size;
143 if (strcmp(ep->d_name, ".")
144 && strcmp(ep->d_name, "..")) {
145 ret = _pkgmgr_calculate_dir_size
149 } else if (S_ISLNK(fileinfo.st_mode)) {
152 /*It is a file. Calculate the actual
153 size occupied (in terms of 4096 blocks)*/
154 q = (fileinfo.st_size / BLOCK_SIZE);
155 r = (fileinfo.st_size % BLOCK_SIZE);
158 total += q * BLOCK_SIZE;
167 static int _pkginfo_add_description_info_into_list(const char *locale,
168 char *record, GList **description)
172 info = calloc(1, sizeof(description_x));
174 LOGE("out of memory");
175 return PMINFO_R_ERROR;
177 info->lang = strdup(locale);
179 *description = g_list_append(*description, info);
184 static int _pkginfo_get_plugin_execution_info(sqlite3 *db, const char *pkgid,
187 static const char query_raw[] =
188 "SELECT appid, plugin_type, plugin_name FROM package_plugin_info "
195 query = sqlite3_mprintf(query_raw, pkgid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query),
204 if (ret != SQLITE_OK) {
205 LOGE("prepare failed: %s", sqlite3_errmsg(db));
206 return PMINFO_R_ERROR;
209 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 plugin = calloc(1, sizeof(plugin_x));
212 LOGE("out of memory");
213 sqlite3_finalize(stmt);
214 return PMINFO_R_ERROR;
216 plugin->pkgid = strdup(pkgid);
217 _save_column_str(stmt, 0, &plugin->appid);
218 _save_column_str(stmt, 1, &plugin->plugin_type);
219 _save_column_str(stmt, 2, &plugin->plugin_name);
220 *plugins = g_list_append(*plugins,
224 sqlite3_finalize(stmt);
229 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
232 static const char query_raw[] =
233 "SELECT DISTINCT privilege, type FROM package_privilege_info "
238 privilege_x *privilege;
240 query = sqlite3_mprintf(query_raw, pkgid);
242 LOGE("out of memory");
243 return PMINFO_R_ERROR;
246 ret = sqlite3_prepare_v2(db, query, strlen(query),
249 if (ret != SQLITE_OK) {
250 LOGE("prepare failed: %s", sqlite3_errmsg(db));
251 return PMINFO_R_ERROR;
254 while (sqlite3_step(stmt) == SQLITE_ROW) {
255 privilege = calloc(1, sizeof(privilege_x));
257 LOGE("failed to alloc memory");
258 sqlite3_finalize(stmt);
259 return PMINFO_R_ERROR;
261 _save_column_str(stmt, 0, &privilege->value);
262 _save_column_str(stmt, 1, &privilege->type);
263 *privileges = g_list_append(*privileges,
264 (gpointer)privilege);
267 sqlite3_finalize(stmt);
272 static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
275 static const char query_raw[] =
276 "SELECT DISTINCT privilege, license, type FROM "
277 "package_appdefined_privilege_info WHERE package=%Q";
281 appdefined_privilege_x *privilege;
283 query = sqlite3_mprintf(query_raw, pkgid);
285 LOGE("out of memory");
286 return PMINFO_R_ERROR;
289 ret = sqlite3_prepare_v2(db, query, strlen(query),
292 if (ret != SQLITE_OK) {
293 LOGE("prepare failed: %s", sqlite3_errmsg(db));
294 return PMINFO_R_ERROR;
297 while (sqlite3_step(stmt) == SQLITE_ROW) {
298 privilege = calloc(1, sizeof(appdefined_privilege_x));
300 LOGE("failed to alloc memory");
301 sqlite3_finalize(stmt);
302 return PMINFO_R_ERROR;
304 _save_column_str(stmt, 0, &privilege->value);
305 _save_column_str(stmt, 1, &privilege->license);
306 _save_column_str(stmt, 2, &privilege->type);
307 *privileges = g_list_append(*privileges,
308 (gpointer)privilege);
311 sqlite3_finalize(stmt);
316 static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid,
317 GList **dependencies)
319 static const char query_raw[] =
320 "SELECT DISTINCT depends_on, type, required_version "
321 "FROM package_dependency_info WHERE package=%Q";
325 dependency_x *dependency;
327 query = sqlite3_mprintf(query_raw, pkgid);
329 LOGE("out of memory");
330 return PMINFO_R_ERROR;
333 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
335 if (ret != SQLITE_OK) {
336 LOGE("prepare failed: %s", sqlite3_errmsg(db));
337 return PMINFO_R_ERROR;
340 while (sqlite3_step(stmt) == SQLITE_ROW) {
341 dependency = calloc(1, sizeof(dependency_x));
343 LOGE("failed to alloc memory");
344 sqlite3_finalize(stmt);
345 return PMINFO_R_ERROR;
347 _save_column_str(stmt, 0, &dependency->depends_on);
348 _save_column_str(stmt, 1, &dependency->type);
349 _save_column_str(stmt, 2, &dependency->required_version);
350 *dependencies = g_list_append(*dependencies,
351 (gpointer)dependency);
354 sqlite3_finalize(stmt);
359 static const char join_localized_info[] =
360 " LEFT OUTER JOIN package_localized_info"
361 " ON pi.package=package_localized_info.package"
362 " AND package_localized_info.package_locale=?";
363 static const char join_privilege_info[] =
364 " LEFT OUTER JOIN package_privilege_info"
365 " ON pi.package=package_privilege_info.package";
367 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
368 const char *locale, uid_t uid, char **query, GList **bind_params)
371 char buf[MAX_QUERY_LEN] = { '\0' };
372 char buf2[MAX_QUERY_LEN] = { '\0' };
373 char *condition = NULL;
379 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
380 for (list = filter->list; list; list = list->next) {
381 joined |= __get_filter_condition(list->data, uid, &condition,
383 if (condition == NULL)
386 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
388 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
393 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
394 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
395 *bind_params = g_list_append(*bind_params, strdup(locale));
397 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
398 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
399 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
401 *query = strdup(buf2);
403 return PMINFO_R_ERROR;
408 static void __free_packages(gpointer data)
410 pkgmgrinfo_basic_free_package((package_x *)data);
413 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
420 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
427 static int __bind_params(sqlite3_stmt *stmt, GList *params)
429 GList *tmp_list = NULL;
433 if (stmt == NULL || params == NULL)
434 return PMINFO_R_EINVAL;
438 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
439 if (ret != SQLITE_OK)
440 return PMINFO_R_ERROR;
441 tmp_list = tmp_list->next;
447 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
449 GSList *tmp_list = NULL;
450 pkgmgrinfo_node_x *tmp_node = NULL;
453 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
454 for (tmp_list = tmp_filter->list; tmp_list != NULL;
455 tmp_list = g_slist_next(tmp_list)) {
456 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
457 if (property == tmp_node->prop) {
458 if (strcmp(tmp_node->value, "true") == 0)
467 static int _pkginfo_get_packages(uid_t uid, const char *locale,
468 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
470 static const char query_raw[] =
471 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
472 static const char query_basic[] =
473 ", pi.package_version, pi.install_location, "
474 "pi.package_removable, pi.package_preload, pi.package_readonly, "
475 "pi.package_update, pi.package_appsetting, pi.package_system, "
476 "pi.package_type, pi.package_size, pi.installed_time, "
477 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
478 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
479 "pi.package_support_disable, pi.package_tep_name, "
480 "pi.package_zip_mount_file, pi.package_support_mode";
481 static const char query_author[] =
482 ", pi.author_name, pi.author_email, pi.author_href";
483 static const char query_label[] =
485 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
486 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
487 static const char query_icon[] =
489 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
490 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
491 static const char query_description[] =
493 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
494 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
495 static const char query_from_clause[] = " FROM package_info as pi";
496 int ret = PMINFO_R_ERROR;
499 char *tmp_record = NULL;
500 char *constraints = NULL;
501 char query[MAX_QUERY_LEN] = { '\0' };
502 package_x *info = NULL;
503 author_x *author = NULL;
504 GList *bind_params = NULL;
506 sqlite3_stmt *stmt = NULL;
507 pkgmgrinfo_filter_x *tmp_filter = NULL;
508 bool is_check_storage = true;
509 const uid_t global_user_uid = GLOBAL_USER;
511 dbpath = getUserPkgParserDBPathUID(uid);
513 return PMINFO_R_ERROR;
515 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
516 if (ret != SQLITE_OK) {
517 _LOGD("failed to open db(%s): %d", dbpath, ret);
519 return PMINFO_R_ERROR;
523 if (filter != NULL) {
526 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
527 if (ret != PMINFO_R_OK) {
528 _LOGE("Failed to create filter");
529 return PMINFO_R_ERROR;
533 is_check_storage = __check_package_storage_status(tmp_filter);
535 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
536 if (flag & PMINFO_APPINFO_GET_BASICINFO)
537 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
538 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
539 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
540 if (flag & PMINFO_PKGINFO_GET_LABEL) {
541 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
542 bind_params = g_list_append(bind_params, strdup(locale));
544 if (flag & PMINFO_PKGINFO_GET_ICON) {
545 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
546 bind_params = g_list_append(bind_params, strdup(locale));
548 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
549 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
550 bind_params = g_list_append(bind_params, strdup(locale));
553 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
555 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
556 if (ret != PMINFO_R_OK) {
557 LOGE("Failed to get WHERE clause");
562 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
564 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
565 if (ret != SQLITE_OK) {
566 LOGE("prepare failed: %s", sqlite3_errmsg(db));
567 ret = PMINFO_R_ERROR;
571 ret = __bind_params(stmt, bind_params);
572 if (ret != SQLITE_OK) {
573 LOGE("Failed to bind parameters");
577 while (sqlite3_step(stmt) == SQLITE_ROW) {
578 info = calloc(1, sizeof(package_x));
580 LOGE("out of memory");
581 ret = PMINFO_R_ERROR;
585 _save_column_str(stmt, idx++, &info->package);
586 _save_column_str(stmt, idx++, &info->installed_storage);
587 _save_column_str(stmt, idx++, &info->external_path);
589 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
590 _save_column_str(stmt, idx++, &info->version);
591 _save_column_str(stmt, idx++, &info->installlocation);
592 _save_column_str(stmt, idx++, &info->removable);
593 _save_column_str(stmt, idx++, &info->preload);
594 _save_column_str(stmt, idx++, &info->readonly);
595 _save_column_str(stmt, idx++, &info->update);
596 _save_column_str(stmt, idx++, &info->appsetting);
597 _save_column_str(stmt, idx++, &info->system);
598 _save_column_str(stmt, idx++, &info->type);
599 _save_column_str(stmt, idx++, &info->package_size);
600 _save_column_str(stmt, idx++, &info->installed_time);
601 _save_column_str(stmt, idx++, &info->storeclient_id);
602 _save_column_str(stmt, idx++, &info->mainapp_id);
603 _save_column_str(stmt, idx++, &info->package_url);
604 _save_column_str(stmt, idx++, &info->root_path);
605 _save_column_str(stmt, idx++, &info->csc_path);
606 _save_column_str(stmt, idx++, &info->nodisplay_setting);
607 _save_column_str(stmt, idx++, &info->api_version);
608 _save_column_str(stmt, idx++, &info->support_disable);
609 _save_column_str(stmt, idx++, &info->tep_name);
610 _save_column_str(stmt, idx++, &info->zip_mount_file);
611 _save_column_str(stmt, idx++, &info->support_mode);
614 info->for_all_users =
615 strdup((uid != global_user_uid) ? "false" : "true");
617 if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) {
618 ret = PMINFO_R_ERROR;
622 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
623 /* TODO : author should be retrieved at package_localized_info */
624 author = calloc(1, sizeof(author_x));
625 if (author == NULL) {
626 ret = PMINFO_R_ERROR;
629 _save_column_str(stmt, idx++, &author->text);
630 _save_column_str(stmt, idx++, &author->email);
631 _save_column_str(stmt, idx++, &author->href);
632 info->author = g_list_append(info->author, author);
635 if (flag & PMINFO_PKGINFO_GET_LABEL) {
637 _save_column_str(stmt, idx++, &tmp_record);
639 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
640 ret = PMINFO_R_ERROR;
645 if (flag & PMINFO_PKGINFO_GET_ICON) {
647 _save_column_str(stmt, idx++, &tmp_record);
648 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
649 ret = PMINFO_R_ERROR;
654 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
656 _save_column_str(stmt, idx++, &tmp_record);
657 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
658 &info->description)) {
659 ret = PMINFO_R_ERROR;
664 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
665 if (_pkginfo_get_privilege(db, info->package,
666 &info->privileges)) {
667 ret = PMINFO_R_ERROR;
672 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
673 if (_pkginfo_get_appdefined_privilege(db, info->package,
674 &info->appdefined_privileges)) {
675 ret = PMINFO_R_ERROR;
680 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
681 if (_pkginfo_get_dependency(db, info->package,
682 &info->dependencies)) {
683 ret = PMINFO_R_ERROR;
688 if (is_check_storage &&
689 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
690 ret = PMINFO_R_ERROR;
691 pkgmgrinfo_basic_free_package(info);
696 g_hash_table_insert(packages, (gpointer)info->package,
703 sqlite3_finalize(stmt);
704 sqlite3_close_v2(db);
709 if (ret != PMINFO_R_OK && info != NULL)
710 pkgmgrinfo_basic_free_package(info);
713 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
715 g_list_free_full(bind_params, free);
720 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
721 pkgmgrinfo_filter_x *filter, int flag,
722 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
727 pkgmgr_pkginfo_x info;
728 pkgmgrinfo_filter_x *tmp_filter = NULL;
733 locale = _get_system_locale();
735 return PMINFO_R_ERROR;
737 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
741 return PMINFO_R_ERROR;
744 if (filter != NULL) {
745 tmp_filter = (pkgmgrinfo_filter_x *)filter;
747 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
748 if (ret != PMINFO_R_OK) {
749 _LOGE("Failed to create filter");
750 g_hash_table_destroy(list);
752 return PMINFO_R_ERROR;
756 if (__check_disable_filter_exist(tmp_filter) == false) {
757 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
758 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
759 if (ret != PMINFO_R_OK) {
760 _LOGE("Failed to add filter");
761 g_hash_table_destroy(list);
764 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
765 return PMINFO_R_ERROR;
769 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
770 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
771 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
772 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
773 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
775 if (ret != PMINFO_R_OK) {
776 g_hash_table_destroy(list);
779 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
780 return PMINFO_R_ERROR;
783 g_hash_table_iter_init(&iter, list);
784 while (g_hash_table_iter_next(&iter, NULL, &value)) {
785 pkg = (package_x *)value;
788 info.locale = locale;
789 if (pkg_list_cb(&info, user_data) < 0)
793 g_hash_table_destroy(list);
797 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
802 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
803 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
808 pkgmgr_pkginfo_x *info;
810 if (pkgid == NULL || filter == NULL || handle == NULL) {
811 LOGE("invalid parameter");
812 return PMINFO_R_EINVAL;
815 locale = _get_system_locale();
817 return PMINFO_R_ERROR;
819 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
823 return PMINFO_R_ERROR;
826 ret = _pkginfo_get_packages(uid, locale, filter,
827 PMINFO_PKGINFO_GET_ALL, list);
828 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
829 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
830 PMINFO_PKGINFO_GET_ALL, list);
832 if (ret != PMINFO_R_OK) {
833 g_hash_table_destroy(list);
838 if (!g_hash_table_size(list)) {
839 _LOGD("pkginfo for [%s] is not existed for user [%d]",
841 g_hash_table_destroy(list);
843 return PMINFO_R_ENOENT;
846 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
848 _LOGE("out of memory");
849 g_hash_table_destroy(list);
851 return PMINFO_R_ERROR;
855 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
856 info->locale = locale;
858 /* just free list only */
859 g_hash_table_steal(list, (gconstpointer)pkgid);
860 g_hash_table_destroy(list);
867 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
868 pkgmgrinfo_pkginfo_h *handle)
871 pkgmgrinfo_pkginfo_filter_h filter;
873 if (pkgid == NULL || handle == NULL) {
874 LOGE("invalid parameter");
875 return PMINFO_R_EINVAL;
878 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
879 if (ret != PMINFO_R_OK)
882 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
883 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
884 if (ret != PMINFO_R_OK) {
885 pkgmgrinfo_pkginfo_filter_destroy(filter);
886 return PMINFO_R_ERROR;
889 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
890 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
891 if (ret != PMINFO_R_OK) {
892 pkgmgrinfo_pkginfo_filter_destroy(filter);
893 return PMINFO_R_ERROR;
896 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
897 pkgmgrinfo_pkginfo_filter_destroy(filter);
902 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
903 pkgmgrinfo_pkginfo_h *handle)
905 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
908 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
909 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
914 pkgmgrinfo_pkginfo_filter_h filter;
915 pkgmgr_pkginfo_x *info;
917 if (pkgid == NULL || handle == NULL) {
918 LOGE("invalid parameter");
919 return PMINFO_R_EINVAL;
922 locale = _get_system_locale();
924 return PMINFO_R_ERROR;
926 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
927 if (ret != PMINFO_R_OK) {
932 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
933 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
934 if (ret != PMINFO_R_OK) {
935 pkgmgrinfo_pkginfo_filter_destroy(filter);
937 return PMINFO_R_ERROR;
940 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
941 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
942 if (ret != PMINFO_R_OK) {
943 pkgmgrinfo_pkginfo_filter_destroy(filter);
945 return PMINFO_R_ERROR;
948 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
951 pkgmgrinfo_pkginfo_filter_destroy(filter);
953 return PMINFO_R_ERROR;
956 ret = _pkginfo_get_packages(uid, locale, filter,
957 PMINFO_PKGINFO_GET_ALL, list);
958 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
959 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
960 PMINFO_PKGINFO_GET_ALL, list);
962 pkgmgrinfo_pkginfo_filter_destroy(filter);
963 if (ret != PMINFO_R_OK) {
964 g_hash_table_destroy(list);
969 if (!g_hash_table_size(list)) {
970 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
972 g_hash_table_destroy(list);
974 return PMINFO_R_ENOENT;
977 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
979 _LOGE("out of memory");
980 g_hash_table_destroy(list);
982 return PMINFO_R_ERROR;
986 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
987 info->locale = locale;
989 /* just free list only */
990 g_hash_table_steal(list, (gconstpointer)pkgid);
991 g_hash_table_destroy(list);
998 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
999 pkgmgrinfo_pkginfo_h *handle)
1003 pkgmgrinfo_pkginfo_filter_h filter;
1005 if (pkgid == NULL || handle == NULL) {
1006 LOGE("invalid parameter");
1007 return PMINFO_R_EINVAL;
1010 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1011 if (ret != PMINFO_R_OK)
1014 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
1015 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
1016 if (ret != PMINFO_R_OK) {
1017 pkgmgrinfo_pkginfo_filter_destroy(filter);
1018 return PMINFO_R_ERROR;
1021 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1022 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
1023 if (ret != PMINFO_R_OK) {
1024 pkgmgrinfo_pkginfo_filter_destroy(filter);
1025 return PMINFO_R_ERROR;
1028 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
1029 pkgmgrinfo_pkginfo_filter_destroy(filter);
1034 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
1035 pkgmgrinfo_pkginfo_h *handle)
1037 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
1041 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
1042 pkgmgrinfo_pkginfo_h *handle)
1044 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
1047 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1048 int flag, void *user_data, uid_t uid)
1051 pkgmgrinfo_pkginfo_filter_h filter;
1053 if (pkg_list_cb == NULL) {
1054 LOGE("invalid parameter");
1055 return PMINFO_R_EINVAL;
1058 /* create an empty filter */
1059 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1060 if (ret != PMINFO_R_OK)
1063 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
1064 pkg_list_cb, user_data);
1066 pkgmgrinfo_pkginfo_filter_destroy(filter);
1071 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1072 int flag, void *user_data)
1074 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
1075 user_data, _getuid());
1078 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1079 void *user_data, uid_t uid)
1082 pkgmgrinfo_pkginfo_filter_h filter;
1084 if (pkg_list_cb == NULL) {
1085 LOGE("invalid parameter");
1086 return PMINFO_R_EINVAL;
1089 /* create an empty filter */
1090 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1091 if (ret != PMINFO_R_OK)
1094 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1095 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1097 pkgmgrinfo_pkginfo_filter_destroy(filter);
1102 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1105 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1109 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1110 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1113 pkgmgrinfo_pkginfo_filter_h filter;
1115 if (pkg_list_cb == NULL) {
1116 LOGE("invalid parameter");
1117 return PMINFO_R_EINVAL;
1120 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1121 if (ret != PMINFO_R_OK)
1124 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1125 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1126 if (ret != PMINFO_R_OK) {
1127 pkgmgrinfo_pkginfo_filter_destroy(filter);
1128 return PMINFO_R_ERROR;
1131 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1132 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1134 pkgmgrinfo_pkginfo_filter_destroy(filter);
1139 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1142 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1146 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1148 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1151 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1153 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1154 return PMINFO_R_ERROR;
1156 *pkg_name = (char *)info->pkg_info->package;
1161 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1163 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1165 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1166 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1168 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1169 return PMINFO_R_ERROR;
1171 *pkgid = (char *)info->pkg_info->package;
1176 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1178 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1181 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1183 if (info->pkg_info == NULL)
1184 return PMINFO_R_ERROR;
1186 if (info->pkg_info->type == NULL)
1189 *type = (char *)info->pkg_info->type;
1194 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1196 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1198 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1199 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1201 if (info->pkg_info == NULL)
1202 return PMINFO_R_ERROR;
1204 if (info->pkg_info->version == NULL)
1207 *version = (char *)info->pkg_info->version;
1212 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1214 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1217 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1219 if (info->pkg_info == NULL)
1220 return PMINFO_R_ERROR;
1222 if (info->pkg_info->api_version == NULL)
1225 *api_version = (char *)info->pkg_info->api_version;
1230 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1232 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1234 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1235 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1237 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1238 return PMINFO_R_ERROR;
1240 *tep_name = (char *)info->pkg_info->tep_name;
1245 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1247 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1249 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1250 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1252 if (info->pkg_info == NULL)
1253 return PMINFO_R_ERROR;
1255 if (info->pkg_info->zip_mount_file == NULL)
1256 *zip_mount_file = "";
1258 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1263 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1265 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1267 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1268 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1270 if (info->pkg_info == NULL)
1271 return PMINFO_R_ERROR;
1273 if (info->pkg_info->external_path == NULL)
1274 return PMINFO_R_ENOENT;
1276 *ext_image_path = (char *)info->pkg_info->external_path;
1281 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1284 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1287 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1289 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1290 return PMINFO_R_ERROR;
1292 val = (char *)info->pkg_info->installlocation;
1293 if (strcmp(val, "internal-only") == 0)
1294 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1295 else if (strcmp(val, "prefer-external") == 0)
1296 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1298 *location = PMINFO_INSTALL_LOCATION_AUTO;
1303 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1305 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1308 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1309 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1311 if (info->pkg_info == NULL)
1312 return PMINFO_R_ERROR;
1314 if (info->pkg_info->package_size == NULL) {
1317 _LOGE("out of memory");
1318 return PMINFO_R_ERROR;
1320 info->pkg_info->package_size = temp;
1324 *size = atoi((char *)info->pkg_info->package_size);
1329 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1332 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1335 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1337 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1338 return PMINFO_R_ERROR;
1340 ptr = (icon_x *)info->pkg_info->icon->data;
1342 return PMINFO_R_ERROR;
1344 /* TODO : should we return empty string if there was no icon? */
1345 if (ptr->text == NULL)
1353 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1356 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1358 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1359 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1361 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1362 return PMINFO_R_ERROR;
1364 ptr = (label_x *)info->pkg_info->label->data;
1366 return PMINFO_R_ERROR;
1368 /* TODO : should we return empty string if there was no label? */
1369 if (ptr->text == NULL)
1377 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1380 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1383 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1385 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1386 return PMINFO_R_ERROR;
1388 ptr = (description_x *)info->pkg_info->description->data;
1390 return PMINFO_R_ERROR;
1392 if (ptr->text == NULL)
1395 *description = (char *)ptr->text;
1400 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1402 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1405 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1406 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1408 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1409 return PMINFO_R_ERROR;
1411 author = (author_x *)info->pkg_info->author->data;
1413 return PMINFO_R_ERROR;
1415 if (author->text == NULL)
1418 *author_name = (char *)author->text;
1423 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1425 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1429 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1431 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1432 return PMINFO_R_ERROR;
1434 author = (author_x *)info->pkg_info->author->data;
1436 return PMINFO_R_ERROR;
1438 if (author->email == NULL)
1441 *author_email = (char *)author->email;
1446 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1448 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1451 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1452 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1454 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1455 return PMINFO_R_ERROR;
1457 author = (author_x *)info->pkg_info->author->data;
1459 return PMINFO_R_ERROR;
1461 if (author->href == NULL)
1464 *author_href = (char *)author->href;
1469 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1471 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1474 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1476 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1477 return PMINFO_R_ERROR;
1479 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1480 *storage = PMINFO_INTERNAL_STORAGE;
1481 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1482 *storage = PMINFO_EXTERNAL_STORAGE;
1483 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1484 *storage = PMINFO_EXTENDED_STORAGE;
1486 return PMINFO_R_ERROR;
1491 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1493 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1496 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1498 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1499 return PMINFO_R_ERROR;
1501 *installed_time = atoi(info->pkg_info->installed_time);
1506 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1508 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1511 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1513 if (info->pkg_info == NULL)
1514 return PMINFO_R_ERROR;
1516 if (info->pkg_info->storeclient_id == NULL)
1517 *storeclientid = "";
1519 *storeclientid = (char *)info->pkg_info->storeclient_id;
1524 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1526 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1529 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1531 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1532 return PMINFO_R_ERROR;
1534 *mainappid = (char *)info->pkg_info->mainapp_id;
1539 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
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(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1546 if (info->pkg_info == NULL)
1547 return PMINFO_R_ERROR;
1549 if (info->pkg_info->package_url == NULL)
1552 *url = (char *)info->pkg_info->package_url;
1557 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1559 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1561 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1562 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1564 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1565 return PMINFO_R_ERROR;
1567 *path = (char *)info->pkg_info->root_path;
1572 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1574 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1576 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1577 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1579 if (info->pkg_info == NULL)
1580 return PMINFO_R_ERROR;
1582 if (info->pkg_info->csc_path == NULL)
1585 *path = (char *)info->pkg_info->csc_path;
1590 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1593 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1595 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1596 if (info->pkg_info->support_mode)
1597 *support_mode = atoi(info->pkg_info->support_mode);
1604 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1607 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1609 #if 0 /* smack issue occured, check later */
1611 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1612 if (pkgid == NULL) {
1613 _LOGD("invalid func parameters\n");
1614 return PMINFO_R_ERROR;
1616 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1619 char app_mmc_path[FILENAME_MAX] = { 0, };
1620 char app_dir_path[FILENAME_MAX] = { 0, };
1621 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1622 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1623 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1624 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1626 /*check whether application is in external memory or not */
1627 fp = fopen(app_mmc_path, "r");
1629 _LOGD(" app path in external memory not accesible\n");
1634 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1638 /*check whether application is in internal or not */
1640 _LOGD(" app path in internal memory not accesible\n");
1642 return PMINFO_R_ERROR;
1645 /*check whether the application is installed in SD card
1646 but SD card is not present*/
1647 fp = fopen(app_mmc_internal_path, "r");
1650 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1654 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1659 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1666 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1668 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1670 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1671 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1673 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1674 return PMINFO_R_ERROR;
1676 *removable = _get_bool_value(info->pkg_info->removable);
1681 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1684 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1686 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1687 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1689 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1690 return PMINFO_R_ERROR;
1692 val = (char *)info->pkg_info->installlocation;
1693 if (strcmp(val, "internal-only") == 0)
1701 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1703 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1706 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1708 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1709 return PMINFO_R_ERROR;
1711 *preload = _get_bool_value(info->pkg_info->preload);
1716 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1718 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1720 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1721 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1723 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1724 return PMINFO_R_ERROR;
1726 *system = _get_bool_value(info->pkg_info->system);
1731 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1733 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1735 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1736 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1738 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1739 return PMINFO_R_ERROR;
1741 *readonly = _get_bool_value(info->pkg_info->readonly);
1746 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1748 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1751 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1753 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1754 return PMINFO_R_ERROR;
1756 *update = _get_bool_value(info->pkg_info->update);
1761 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1763 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1765 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1766 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1768 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1769 return PMINFO_R_ERROR;
1771 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1776 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1778 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1781 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1783 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1784 return PMINFO_R_ERROR;
1786 *global = _get_bool_value(info->pkg_info->for_all_users);
1791 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1793 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1796 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1798 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1802 __cleanup_pkginfo(info);
1807 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1809 pkgmgrinfo_filter_x *filter;
1811 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1813 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1814 if (filter == NULL) {
1815 _LOGE("Out of Memory!!!");
1816 return PMINFO_R_ERROR;
1824 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1826 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1831 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1832 g_slist_free(filter->list);
1835 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1842 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1843 const char *property, const int value)
1845 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1849 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1850 pkgmgrinfo_node_x *node;
1852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1853 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1855 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1856 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1857 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1858 _LOGE("Invalid Integer Property\n");
1859 return PMINFO_R_EINVAL;
1861 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1863 _LOGE("Out of Memory!!!\n");
1864 return PMINFO_R_ERROR;
1866 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1867 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1869 _LOGE("Out of Memory\n");
1871 return PMINFO_R_ERROR;
1875 /*If API is called multiple times for same property, we should override the previous values.
1876 Last value set will be used for filtering.*/
1877 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1879 filter->list = g_slist_delete_link(filter->list, link);
1880 filter->list = g_slist_append(filter->list, (gpointer)node);
1885 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1886 const char *property, const bool value)
1891 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1892 pkgmgrinfo_node_x *node;
1894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1895 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1897 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1898 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1899 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1900 _LOGE("Invalid Boolean Property\n");
1901 return PMINFO_R_EINVAL;
1903 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1905 _LOGE("Out of Memory!!!\n");
1906 return PMINFO_R_ERROR;
1909 val = strndup("true", 4);
1911 val = strndup("false", 5);
1913 _LOGE("Out of Memory\n");
1915 return PMINFO_R_ERROR;
1919 /*If API is called multiple times for same property, we should override the previous values.
1920 Last value set will be used for filtering.*/
1921 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1923 filter->list = g_slist_delete_link(filter->list, link);
1924 filter->list = g_slist_append(filter->list, (gpointer)node);
1929 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1930 const char *property, const char *value)
1935 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1936 pkgmgrinfo_node_x *node;
1938 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1939 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1940 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1942 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1943 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1944 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1945 _LOGE("Invalid String Property\n");
1946 return PMINFO_R_EINVAL;
1948 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1950 _LOGE("Out of Memory!!!\n");
1951 return PMINFO_R_ERROR;
1953 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1954 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1955 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1956 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1957 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1958 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1959 else if (strcmp(value, "installed_internal") == 0)
1960 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1961 else if (strcmp(value, "installed_external") == 0)
1962 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1964 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1966 _LOGE("Out of Memory\n");
1968 return PMINFO_R_ERROR;
1972 /*If API is called multiple times for same property, we should override the previous values.
1973 Last value set will be used for filtering.*/
1974 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1976 filter->list = g_slist_delete_link(filter->list, link);
1977 filter->list = g_slist_append(filter->list, (gpointer)node);
1982 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1986 GHashTable *list = NULL;
1988 if (handle == NULL || count == NULL) {
1989 _LOGE("invalid parameter");
1990 return PMINFO_R_EINVAL;
1993 locale = _get_system_locale();
1995 return PMINFO_R_ERROR;
1997 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
2001 return PMINFO_R_ERROR;
2004 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
2005 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
2006 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
2007 if (ret != PMINFO_R_OK) {
2009 g_hash_table_destroy(list);
2010 return PMINFO_R_ERROR;
2014 ret = _pkginfo_get_packages(uid, locale,
2015 (pkgmgrinfo_filter_x *)handle, 0, list);
2016 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
2017 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
2020 if (ret != PMINFO_R_OK) {
2021 g_hash_table_destroy(list);
2023 return PMINFO_R_ERROR;
2026 *count = g_hash_table_size(list);
2028 g_hash_table_destroy(list);
2034 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
2036 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
2039 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
2040 pkgmgrinfo_pkginfo_filter_h handle,
2041 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
2043 if (handle == NULL || pkg_cb == NULL) {
2044 LOGE("invalid parameter");
2045 return PMINFO_R_EINVAL;
2048 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
2049 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
2052 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
2053 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2055 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2058 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2059 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2062 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2064 privilege_x *privilege;
2065 appdefined_privilege_x *appdefined_privilege;
2067 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2069 if (info->pkg_info == NULL)
2070 return PMINFO_R_ERROR;
2072 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2073 privilege = (privilege_x *)tmp->data;
2074 if (privilege == NULL)
2076 ret = privilege_func(privilege->value, user_data);
2081 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2083 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
2084 if (appdefined_privilege == NULL)
2086 ret = privilege_func(appdefined_privilege->value, user_data);
2093 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
2094 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
2096 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2097 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
2098 "Callback function is NULL");
2102 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2104 if (info->pkg_info == NULL)
2105 return PMINFO_R_ERROR;
2107 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
2108 plugin = (plugin_x *)tmp->data;
2111 ret = plugin_func(plugin->pkgid, plugin->appid,
2112 plugin->plugin_type, plugin->plugin_name, user_data);
2120 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
2121 pkgmgrinfo_pkginfo_h handle,
2122 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
2125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2126 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
2127 "Callback function is NULL");
2129 appdefined_privilege_x *privilege;
2131 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2133 if (info->pkg_info == NULL)
2134 return PMINFO_R_ERROR;
2136 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2138 privilege = (appdefined_privilege_x *)tmp->data;
2139 if (privilege == NULL)
2141 ret = privilege_func(privilege->value, privilege->license,
2149 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
2150 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2154 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2156 dependency_x *dependency;
2158 if (handle == NULL || dependency_cb == NULL) {
2159 LOGE("invalid parameter");
2160 return PMINFO_R_EINVAL;
2163 if (info->pkg_info == NULL)
2164 return PMINFO_R_ERROR;
2166 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
2167 dependency = (dependency_x *)tmp->data;
2168 if (dependency == NULL)
2170 ret = dependency_cb(info->pkg_info->package,
2171 dependency->depends_on, dependency->type,
2172 dependency->required_version, user_data);
2187 static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue,
2188 GHashTable **table, GList **pkg_list)
2190 static const char query[] =
2191 "SELECT package, depends_on, type, required_version "
2192 "FROM package_dependency_info WHERE depends_on=?";
2195 struct depends_on *req;
2197 /* already checked */
2198 if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
2201 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2202 if (ret != SQLITE_OK) {
2203 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2204 return PMINFO_R_ERROR;
2207 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
2208 if (ret != SQLITE_OK) {
2209 LOGE("bind failed: %s", sqlite3_errmsg(db));
2210 sqlite3_finalize(stmt);
2211 return PMINFO_R_ERROR;
2214 while (sqlite3_step(stmt) == SQLITE_ROW) {
2215 req = calloc(1, sizeof(struct depends_on));
2217 LOGE("out of memory");
2218 sqlite3_finalize(stmt);
2219 return PMINFO_R_ERROR;
2221 _save_column_str(stmt, 0, &req->from);
2222 _save_column_str(stmt, 1, &req->to);
2223 _save_column_str(stmt, 2, &req->type);
2224 _save_column_str(stmt, 3, &req->version);
2226 *pkg_list = g_list_append(*pkg_list, req);
2227 g_queue_push_tail(*queue, strdup(req->from));
2230 sqlite3_finalize(stmt);
2235 static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid,
2245 dbpath = getUserPkgParserDBPathUID(uid);
2247 return PMINFO_R_ERROR;
2249 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2250 if (ret != SQLITE_OK) {
2251 LOGD("failed to open db(%s): %d", dbpath, ret);
2253 return PMINFO_R_ERROR;
2257 queue = g_queue_new();
2258 if (queue == NULL) {
2259 LOGE("out of memory");
2260 sqlite3_close_v2(db);
2261 return PMINFO_R_ERROR;
2264 table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
2266 g_queue_push_tail(queue, strdup(pkgid));
2267 while (!g_queue_is_empty(queue)) {
2268 item = g_queue_pop_head(queue);
2269 ret = _get_depends_on(db, item, &queue, &table, pkg_list);
2271 if (ret != PMINFO_R_OK) {
2272 LOGE("failed to get pkgs depends on %s", pkgid);
2273 g_hash_table_destroy(table);
2274 g_queue_free_full(queue, free);
2275 sqlite3_close_v2(db);
2276 return PMINFO_R_ERROR;
2280 g_hash_table_destroy(table);
2281 g_queue_free_full(queue, free);
2282 sqlite3_close_v2(db);
2287 static void __free_depends_on(gpointer data)
2289 struct depends_on *dep = (struct depends_on *)data;
2298 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
2299 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2303 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2304 GList *pkg_list = NULL;
2306 struct depends_on *dep;
2308 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
2309 LOGE("invalid parameter");
2310 return PMINFO_R_EINVAL;
2313 ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package,
2315 if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
2316 ret = _pkginfo_foreach_depends_on(GLOBAL_USER,
2317 info->pkg_info->package, &pkg_list);
2319 if (ret != PMINFO_R_OK) {
2320 g_list_free_full(pkg_list, __free_depends_on);
2324 for (l = pkg_list; l != NULL; l = l->next) {
2325 dep = (struct depends_on *)l->data;
2326 ret = dependency_cb(dep->from, dep->to, dep->type, dep->version,
2332 g_list_free_full(pkg_list, __free_depends_on);
2337 int __compare_package_version(const char *version, int *major,
2338 int *minor, int *macro, int *nano)
2340 char *version_temp = NULL;
2341 char *major_str = NULL;
2342 char *minor_str = NULL;
2343 char *macro_str = NULL;
2344 char *nano_str = NULL;
2345 char *save_str = NULL;
2347 if (version == NULL || major == NULL || minor == NULL ||
2348 macro == NULL || nano == NULL) {
2349 return PMINFO_R_EINVAL;
2352 version_temp = strdup(version);
2353 if (version_temp == NULL) {
2354 LOGE("Out of memory");
2355 return PMINFO_R_ERROR;
2358 major_str = strtok_r(version_temp, ".", &save_str);
2359 if (major_str == NULL) {
2360 _LOGE("major version is NULL");
2362 return PMINFO_R_ERROR;
2365 minor_str = strtok_r(NULL, ".", &save_str);
2366 if (minor_str == NULL) {
2367 _LOGE("minor version is NULL");
2369 return PMINFO_R_ERROR;
2372 *major = atoi(major_str);
2373 *minor = atoi(minor_str);
2376 macro_str = strtok_r(NULL, ".", &save_str);
2377 if (macro_str == NULL) {
2378 _LOGD("macro version is NULL");
2380 *macro = atoi(macro_str);
2381 nano_str = strtok_r(NULL, ".", &save_str);
2383 *nano = atoi(nano_str);
2384 _LOGD("nano version exists");
2387 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2388 " macro = [%d], nano = [%d]", version, *major,
2389 *minor, *macro, *nano);
2396 API int pkgmgrinfo_compare_package_version(const char *current_version,
2397 const char *target_version,
2398 pkgmgrinfo_version_compare_type *res)
2401 int current_version_major = 0;
2402 int current_version_minor = 0;
2403 int current_version_macro = 0;
2404 int current_version_nano = 0;
2405 int target_version_major = 0;
2406 int target_version_minor = 0;
2407 int target_version_macro = 0;
2408 int target_version_nano = 0;
2410 if (current_version == NULL || target_version == NULL ||
2412 _LOGE("Invalid parameter");
2413 return PMINFO_R_EINVAL;
2416 ret = __compare_package_version(target_version,
2417 &target_version_major, &target_version_minor,
2418 &target_version_macro, &target_version_nano);
2420 _LOGE("Failed to compare target version(%d)", ret);
2421 return PMINFO_R_ERROR;
2424 ret = __compare_package_version(current_version,
2425 ¤t_version_major, ¤t_version_minor,
2426 ¤t_version_macro, ¤t_version_nano);
2428 _LOGE("Failed to compare current version(%d)", ret);
2429 return PMINFO_R_ERROR;
2432 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2433 target_version_minor, target_version_macro,
2434 target_version_nano, current_version_major,
2435 current_version_minor, current_version_macro,
2436 target_version_nano);
2438 if (target_version_major > current_version_major)
2439 *res = PMINFO_VERSION_NEW;
2440 else if (target_version_major < current_version_major)
2441 *res = PMINFO_VERSION_OLD;
2442 else if (target_version_minor > current_version_minor)
2443 *res = PMINFO_VERSION_NEW;
2444 else if (target_version_minor < current_version_minor)
2445 *res = PMINFO_VERSION_OLD;
2446 else if (target_version_macro > current_version_macro)
2447 *res = PMINFO_VERSION_NEW;
2448 else if (target_version_macro < current_version_macro)
2449 *res = PMINFO_VERSION_OLD;
2450 else if (target_version_nano > current_version_nano)
2451 *res = PMINFO_VERSION_NEW;
2452 else if (target_version_nano < current_version_nano)
2453 *res = PMINFO_VERSION_OLD;
2455 *res = PMINFO_VERSION_SAME;