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)
372 char buf[MAX_QUERY_LEN] = { '\0' };
373 char buf2[MAX_QUERY_LEN] = { '\0' };
374 char *condition = NULL;
380 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
381 for (list = filter->list; list; list = list->next) {
382 joined |= __get_filter_condition(list->data, uid, &condition,
384 if (condition == NULL)
387 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
389 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
394 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
395 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
396 *bind_params = g_list_append(*bind_params, strdup(locale));
398 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
399 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
401 size = strlen(buf2) + strlen(buf) + 1;
402 *query = (char *)calloc(1, size);
404 return PMINFO_R_ERROR;
405 snprintf(*query, size, "%s%s", buf2, buf);
410 static void __free_packages(gpointer data)
412 pkgmgrinfo_basic_free_package((package_x *)data);
415 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
422 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
429 static int __bind_params(sqlite3_stmt *stmt, GList *params)
431 GList *tmp_list = NULL;
435 if (stmt == NULL || params == NULL)
436 return PMINFO_R_EINVAL;
440 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
441 if (ret != SQLITE_OK)
442 return PMINFO_R_ERROR;
443 tmp_list = tmp_list->next;
449 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
451 GSList *tmp_list = NULL;
452 pkgmgrinfo_node_x *tmp_node = NULL;
455 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
456 for (tmp_list = tmp_filter->list; tmp_list != NULL;
457 tmp_list = g_slist_next(tmp_list)) {
458 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
459 if (property == tmp_node->prop) {
460 if (strcmp(tmp_node->value, "true") == 0)
469 static int _pkginfo_get_packages(uid_t uid, const char *locale,
470 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
472 static const char query_raw[] =
473 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
474 static const char query_basic[] =
475 ", pi.package_version, pi.install_location, "
476 "pi.package_removable, pi.package_preload, pi.package_readonly, "
477 "pi.package_update, pi.package_appsetting, pi.package_system, "
478 "pi.package_type, pi.package_size, pi.installed_time, "
479 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
480 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
481 "pi.package_support_disable, pi.package_tep_name, "
482 "pi.package_zip_mount_file, pi.package_support_mode";
483 static const char query_author[] =
484 ", pi.author_name, pi.author_email, pi.author_href";
485 static const char query_label[] =
487 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
488 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
489 static const char query_icon[] =
491 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
492 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
493 static const char query_description[] =
495 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
496 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
497 static const char query_from_clause[] = " FROM package_info as pi";
498 int ret = PMINFO_R_ERROR;
501 char *tmp_record = NULL;
502 char *constraints = NULL;
503 char query[MAX_QUERY_LEN] = { '\0' };
504 package_x *info = NULL;
505 author_x *author = NULL;
506 GList *bind_params = NULL;
508 sqlite3_stmt *stmt = NULL;
509 pkgmgrinfo_filter_x *tmp_filter = NULL;
510 bool is_check_storage = true;
511 const uid_t global_user_uid = GLOBAL_USER;
513 dbpath = getUserPkgParserDBPathUID(uid);
515 return PMINFO_R_ERROR;
517 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
518 if (ret != SQLITE_OK) {
519 _LOGD("failed to open db(%s): %d", dbpath, ret);
521 return PMINFO_R_ERROR;
525 if (filter != NULL) {
528 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
529 if (ret != PMINFO_R_OK) {
530 _LOGE("Failed to create filter");
531 return PMINFO_R_ERROR;
535 is_check_storage = __check_package_storage_status(tmp_filter);
537 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
538 if (flag & PMINFO_APPINFO_GET_BASICINFO)
539 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
540 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
541 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
542 if (flag & PMINFO_PKGINFO_GET_LABEL) {
543 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
544 bind_params = g_list_append(bind_params, strdup(locale));
546 if (flag & PMINFO_PKGINFO_GET_ICON) {
547 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
548 bind_params = g_list_append(bind_params, strdup(locale));
550 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
551 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
552 bind_params = g_list_append(bind_params, strdup(locale));
555 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
557 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
558 if (ret != PMINFO_R_OK) {
559 LOGE("Failed to get WHERE clause");
564 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
566 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
567 if (ret != SQLITE_OK) {
568 LOGE("prepare failed: %s", sqlite3_errmsg(db));
569 ret = PMINFO_R_ERROR;
573 ret = __bind_params(stmt, bind_params);
574 if (ret != SQLITE_OK) {
575 LOGE("Failed to bind parameters");
579 while (sqlite3_step(stmt) == SQLITE_ROW) {
580 info = calloc(1, sizeof(package_x));
582 LOGE("out of memory");
583 ret = PMINFO_R_ERROR;
587 _save_column_str(stmt, idx++, &info->package);
588 _save_column_str(stmt, idx++, &info->installed_storage);
589 _save_column_str(stmt, idx++, &info->external_path);
591 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
592 _save_column_str(stmt, idx++, &info->version);
593 _save_column_str(stmt, idx++, &info->installlocation);
594 _save_column_str(stmt, idx++, &info->removable);
595 _save_column_str(stmt, idx++, &info->preload);
596 _save_column_str(stmt, idx++, &info->readonly);
597 _save_column_str(stmt, idx++, &info->update);
598 _save_column_str(stmt, idx++, &info->appsetting);
599 _save_column_str(stmt, idx++, &info->system);
600 _save_column_str(stmt, idx++, &info->type);
601 _save_column_str(stmt, idx++, &info->package_size);
602 _save_column_str(stmt, idx++, &info->installed_time);
603 _save_column_str(stmt, idx++, &info->storeclient_id);
604 _save_column_str(stmt, idx++, &info->mainapp_id);
605 _save_column_str(stmt, idx++, &info->package_url);
606 _save_column_str(stmt, idx++, &info->root_path);
607 _save_column_str(stmt, idx++, &info->csc_path);
608 _save_column_str(stmt, idx++, &info->nodisplay_setting);
609 _save_column_str(stmt, idx++, &info->api_version);
610 _save_column_str(stmt, idx++, &info->support_disable);
611 _save_column_str(stmt, idx++, &info->tep_name);
612 _save_column_str(stmt, idx++, &info->zip_mount_file);
613 _save_column_str(stmt, idx++, &info->support_mode);
616 info->for_all_users =
617 strdup((uid != global_user_uid) ? "false" : "true");
619 if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) {
620 ret = PMINFO_R_ERROR;
624 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
625 /* TODO : author should be retrieved at package_localized_info */
626 author = calloc(1, sizeof(author_x));
627 if (author == NULL) {
628 ret = PMINFO_R_ERROR;
631 _save_column_str(stmt, idx++, &author->text);
632 _save_column_str(stmt, idx++, &author->email);
633 _save_column_str(stmt, idx++, &author->href);
634 info->author = g_list_append(info->author, author);
637 if (flag & PMINFO_PKGINFO_GET_LABEL) {
639 _save_column_str(stmt, idx++, &tmp_record);
641 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
642 ret = PMINFO_R_ERROR;
647 if (flag & PMINFO_PKGINFO_GET_ICON) {
649 _save_column_str(stmt, idx++, &tmp_record);
650 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
651 ret = PMINFO_R_ERROR;
656 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
658 _save_column_str(stmt, idx++, &tmp_record);
659 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
660 &info->description)) {
661 ret = PMINFO_R_ERROR;
666 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
667 if (_pkginfo_get_privilege(db, info->package,
668 &info->privileges)) {
669 ret = PMINFO_R_ERROR;
674 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
675 if (_pkginfo_get_appdefined_privilege(db, info->package,
676 &info->appdefined_privileges)) {
677 ret = PMINFO_R_ERROR;
682 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
683 if (_pkginfo_get_dependency(db, info->package,
684 &info->dependencies)) {
685 ret = PMINFO_R_ERROR;
690 if (is_check_storage &&
691 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
692 ret = PMINFO_R_ERROR;
693 pkgmgrinfo_basic_free_package(info);
698 g_hash_table_insert(packages, (gpointer)info->package,
705 sqlite3_finalize(stmt);
706 sqlite3_close_v2(db);
711 if (ret != PMINFO_R_OK && info != NULL)
712 pkgmgrinfo_basic_free_package(info);
715 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
717 g_list_free_full(bind_params, free);
722 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
723 pkgmgrinfo_filter_x *filter, int flag,
724 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
729 pkgmgr_pkginfo_x info;
730 pkgmgrinfo_filter_x *tmp_filter = NULL;
735 locale = _get_system_locale();
737 return PMINFO_R_ERROR;
739 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
743 return PMINFO_R_ERROR;
746 if (filter != NULL) {
747 tmp_filter = (pkgmgrinfo_filter_x *)filter;
749 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
750 if (ret != PMINFO_R_OK) {
751 _LOGE("Failed to create filter");
752 g_hash_table_destroy(list);
754 return PMINFO_R_ERROR;
758 if (__check_disable_filter_exist(tmp_filter) == false) {
759 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
760 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
761 if (ret != PMINFO_R_OK) {
762 _LOGE("Failed to add filter");
763 g_hash_table_destroy(list);
766 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
767 return PMINFO_R_ERROR;
771 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
772 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
773 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
774 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
775 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
777 if (ret != PMINFO_R_OK) {
778 g_hash_table_destroy(list);
781 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
782 return PMINFO_R_ERROR;
785 g_hash_table_iter_init(&iter, list);
786 while (g_hash_table_iter_next(&iter, NULL, &value)) {
787 pkg = (package_x *)value;
790 info.locale = locale;
791 if (pkg_list_cb(&info, user_data) < 0)
795 g_hash_table_destroy(list);
799 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
804 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
805 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
810 pkgmgr_pkginfo_x *info;
812 if (pkgid == NULL || filter == NULL || handle == NULL) {
813 LOGE("invalid parameter");
814 return PMINFO_R_EINVAL;
817 locale = _get_system_locale();
819 return PMINFO_R_ERROR;
821 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
825 return PMINFO_R_ERROR;
828 ret = _pkginfo_get_packages(uid, locale, filter,
829 PMINFO_PKGINFO_GET_ALL, list);
830 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
831 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
832 PMINFO_PKGINFO_GET_ALL, list);
834 if (ret != PMINFO_R_OK) {
835 g_hash_table_destroy(list);
840 if (!g_hash_table_size(list)) {
841 _LOGD("pkginfo for [%s] is not existed for user [%d]",
843 g_hash_table_destroy(list);
845 return PMINFO_R_ENOENT;
848 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
850 _LOGE("out of memory");
851 g_hash_table_destroy(list);
853 return PMINFO_R_ERROR;
857 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
858 info->locale = locale;
860 /* just free list only */
861 g_hash_table_steal(list, (gconstpointer)pkgid);
862 g_hash_table_destroy(list);
869 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
870 pkgmgrinfo_pkginfo_h *handle)
873 pkgmgrinfo_pkginfo_filter_h filter;
875 if (pkgid == NULL || handle == NULL) {
876 LOGE("invalid parameter");
877 return PMINFO_R_EINVAL;
880 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
881 if (ret != PMINFO_R_OK)
884 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
885 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
886 if (ret != PMINFO_R_OK) {
887 pkgmgrinfo_pkginfo_filter_destroy(filter);
888 return PMINFO_R_ERROR;
891 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
892 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
893 if (ret != PMINFO_R_OK) {
894 pkgmgrinfo_pkginfo_filter_destroy(filter);
895 return PMINFO_R_ERROR;
898 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
899 pkgmgrinfo_pkginfo_filter_destroy(filter);
904 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
905 pkgmgrinfo_pkginfo_h *handle)
907 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
910 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
911 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
916 pkgmgrinfo_pkginfo_filter_h filter;
917 pkgmgr_pkginfo_x *info;
919 if (pkgid == NULL || handle == NULL) {
920 LOGE("invalid parameter");
921 return PMINFO_R_EINVAL;
924 locale = _get_system_locale();
926 return PMINFO_R_ERROR;
928 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
929 if (ret != PMINFO_R_OK) {
934 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
935 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
936 if (ret != PMINFO_R_OK) {
937 pkgmgrinfo_pkginfo_filter_destroy(filter);
939 return PMINFO_R_ERROR;
942 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
943 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
944 if (ret != PMINFO_R_OK) {
945 pkgmgrinfo_pkginfo_filter_destroy(filter);
947 return PMINFO_R_ERROR;
950 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
953 pkgmgrinfo_pkginfo_filter_destroy(filter);
955 return PMINFO_R_ERROR;
958 ret = _pkginfo_get_packages(uid, locale, filter,
959 PMINFO_PKGINFO_GET_ALL, list);
960 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
961 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
962 PMINFO_PKGINFO_GET_ALL, list);
964 pkgmgrinfo_pkginfo_filter_destroy(filter);
965 if (ret != PMINFO_R_OK) {
966 g_hash_table_destroy(list);
971 if (!g_hash_table_size(list)) {
972 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
974 g_hash_table_destroy(list);
976 return PMINFO_R_ENOENT;
979 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
981 _LOGE("out of memory");
982 g_hash_table_destroy(list);
984 return PMINFO_R_ERROR;
988 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
989 info->locale = locale;
991 /* just free list only */
992 g_hash_table_steal(list, (gconstpointer)pkgid);
993 g_hash_table_destroy(list);
1000 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
1001 pkgmgrinfo_pkginfo_h *handle)
1005 pkgmgrinfo_pkginfo_filter_h filter;
1007 if (pkgid == NULL || handle == NULL) {
1008 LOGE("invalid parameter");
1009 return PMINFO_R_EINVAL;
1012 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1013 if (ret != PMINFO_R_OK)
1016 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
1017 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
1018 if (ret != PMINFO_R_OK) {
1019 pkgmgrinfo_pkginfo_filter_destroy(filter);
1020 return PMINFO_R_ERROR;
1023 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1024 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
1025 if (ret != PMINFO_R_OK) {
1026 pkgmgrinfo_pkginfo_filter_destroy(filter);
1027 return PMINFO_R_ERROR;
1030 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
1031 pkgmgrinfo_pkginfo_filter_destroy(filter);
1036 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
1037 pkgmgrinfo_pkginfo_h *handle)
1039 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
1043 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
1044 pkgmgrinfo_pkginfo_h *handle)
1046 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
1049 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1050 int flag, void *user_data, uid_t uid)
1053 pkgmgrinfo_pkginfo_filter_h filter;
1055 if (pkg_list_cb == NULL) {
1056 LOGE("invalid parameter");
1057 return PMINFO_R_EINVAL;
1060 /* create an empty filter */
1061 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1062 if (ret != PMINFO_R_OK)
1065 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
1066 pkg_list_cb, user_data);
1068 pkgmgrinfo_pkginfo_filter_destroy(filter);
1073 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1074 int flag, void *user_data)
1076 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
1077 user_data, _getuid());
1080 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1081 void *user_data, uid_t uid)
1084 pkgmgrinfo_pkginfo_filter_h filter;
1086 if (pkg_list_cb == NULL) {
1087 LOGE("invalid parameter");
1088 return PMINFO_R_EINVAL;
1091 /* create an empty filter */
1092 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1093 if (ret != PMINFO_R_OK)
1096 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1097 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1099 pkgmgrinfo_pkginfo_filter_destroy(filter);
1104 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1107 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1111 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1112 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1115 pkgmgrinfo_pkginfo_filter_h filter;
1117 if (pkg_list_cb == NULL) {
1118 LOGE("invalid parameter");
1119 return PMINFO_R_EINVAL;
1122 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1123 if (ret != PMINFO_R_OK)
1126 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1127 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1128 if (ret != PMINFO_R_OK) {
1129 pkgmgrinfo_pkginfo_filter_destroy(filter);
1130 return PMINFO_R_ERROR;
1133 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1134 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1136 pkgmgrinfo_pkginfo_filter_destroy(filter);
1141 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1144 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1148 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1150 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1152 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1153 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1155 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1156 return PMINFO_R_ERROR;
1158 *pkg_name = (char *)info->pkg_info->package;
1163 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1168 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1170 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1171 return PMINFO_R_ERROR;
1173 *pkgid = (char *)info->pkg_info->package;
1178 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1180 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1182 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1183 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1185 if (info->pkg_info == NULL)
1186 return PMINFO_R_ERROR;
1188 if (info->pkg_info->type == NULL)
1191 *type = (char *)info->pkg_info->type;
1196 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1198 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1201 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1203 if (info->pkg_info == NULL)
1204 return PMINFO_R_ERROR;
1206 if (info->pkg_info->version == NULL)
1209 *version = (char *)info->pkg_info->version;
1214 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1216 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1219 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1221 if (info->pkg_info == NULL)
1222 return PMINFO_R_ERROR;
1224 if (info->pkg_info->api_version == NULL)
1227 *api_version = (char *)info->pkg_info->api_version;
1232 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1234 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1237 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1240 return PMINFO_R_ERROR;
1242 *tep_name = (char *)info->pkg_info->tep_name;
1247 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1249 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1251 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1252 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1254 if (info->pkg_info == NULL)
1255 return PMINFO_R_ERROR;
1257 if (info->pkg_info->zip_mount_file == NULL)
1258 *zip_mount_file = "";
1260 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1265 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1267 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1269 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1270 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1272 if (info->pkg_info == NULL)
1273 return PMINFO_R_ERROR;
1275 if (info->pkg_info->external_path == NULL)
1276 return PMINFO_R_ENOENT;
1278 *ext_image_path = (char *)info->pkg_info->external_path;
1283 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1286 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1289 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1291 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1292 return PMINFO_R_ERROR;
1294 val = (char *)info->pkg_info->installlocation;
1295 if (strcmp(val, "internal-only") == 0)
1296 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1297 else if (strcmp(val, "prefer-external") == 0)
1298 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1300 *location = PMINFO_INSTALL_LOCATION_AUTO;
1305 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1307 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1310 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1311 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1313 if (info->pkg_info == NULL)
1314 return PMINFO_R_ERROR;
1316 if (info->pkg_info->package_size == NULL) {
1319 _LOGE("out of memory");
1320 return PMINFO_R_ERROR;
1322 info->pkg_info->package_size = temp;
1326 *size = atoi((char *)info->pkg_info->package_size);
1331 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1334 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1336 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1337 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1339 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1340 return PMINFO_R_ERROR;
1342 ptr = (icon_x *)info->pkg_info->icon->data;
1344 return PMINFO_R_ERROR;
1346 /* TODO : should we return empty string if there was no icon? */
1347 if (ptr->text == NULL)
1355 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1358 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1361 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1363 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1364 return PMINFO_R_ERROR;
1366 ptr = (label_x *)info->pkg_info->label->data;
1368 return PMINFO_R_ERROR;
1370 /* TODO : should we return empty string if there was no label? */
1371 if (ptr->text == NULL)
1379 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1384 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1385 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1387 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1388 return PMINFO_R_ERROR;
1390 ptr = (description_x *)info->pkg_info->description->data;
1392 return PMINFO_R_ERROR;
1394 if (ptr->text == NULL)
1397 *description = (char *)ptr->text;
1402 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1404 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1407 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1408 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1410 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1411 return PMINFO_R_ERROR;
1413 author = (author_x *)info->pkg_info->author->data;
1415 return PMINFO_R_ERROR;
1417 if (author->text == NULL)
1420 *author_name = (char *)author->text;
1425 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1427 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1430 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1431 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1433 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1434 return PMINFO_R_ERROR;
1436 author = (author_x *)info->pkg_info->author->data;
1438 return PMINFO_R_ERROR;
1440 if (author->email == NULL)
1443 *author_email = (char *)author->email;
1448 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1450 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1453 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1454 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1456 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1457 return PMINFO_R_ERROR;
1459 author = (author_x *)info->pkg_info->author->data;
1461 return PMINFO_R_ERROR;
1463 if (author->href == NULL)
1466 *author_href = (char *)author->href;
1471 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1473 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1476 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1478 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1479 return PMINFO_R_ERROR;
1481 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1482 *storage = PMINFO_INTERNAL_STORAGE;
1483 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1484 *storage = PMINFO_EXTERNAL_STORAGE;
1485 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1486 *storage = PMINFO_EXTENDED_STORAGE;
1488 return PMINFO_R_ERROR;
1493 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1495 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1497 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1498 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1500 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1501 return PMINFO_R_ERROR;
1503 *installed_time = atoi(info->pkg_info->installed_time);
1508 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1510 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1512 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1513 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1515 if (info->pkg_info == NULL)
1516 return PMINFO_R_ERROR;
1518 if (info->pkg_info->storeclient_id == NULL)
1519 *storeclientid = "";
1521 *storeclientid = (char *)info->pkg_info->storeclient_id;
1526 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1528 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1531 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1533 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1534 return PMINFO_R_ERROR;
1536 *mainappid = (char *)info->pkg_info->mainapp_id;
1541 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1543 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1545 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1546 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1548 if (info->pkg_info == NULL)
1549 return PMINFO_R_ERROR;
1551 if (info->pkg_info->package_url == NULL)
1554 *url = (char *)info->pkg_info->package_url;
1559 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1561 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1564 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1566 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1567 return PMINFO_R_ERROR;
1569 *path = (char *)info->pkg_info->root_path;
1574 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1576 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1579 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1581 if (info->pkg_info == NULL)
1582 return PMINFO_R_ERROR;
1584 if (info->pkg_info->csc_path == NULL)
1587 *path = (char *)info->pkg_info->csc_path;
1592 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1595 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1597 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1598 if (info->pkg_info->support_mode)
1599 *support_mode = atoi(info->pkg_info->support_mode);
1606 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1609 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1611 #if 0 /* smack issue occured, check later */
1613 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1614 if (pkgid == NULL) {
1615 _LOGD("invalid func parameters\n");
1616 return PMINFO_R_ERROR;
1618 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1621 char app_mmc_path[FILENAME_MAX] = { 0, };
1622 char app_dir_path[FILENAME_MAX] = { 0, };
1623 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1624 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1625 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1626 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1628 /*check whether application is in external memory or not */
1629 fp = fopen(app_mmc_path, "r");
1631 _LOGD(" app path in external memory not accesible\n");
1636 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1640 /*check whether application is in internal or not */
1642 _LOGD(" app path in internal memory not accesible\n");
1644 return PMINFO_R_ERROR;
1647 /*check whether the application is installed in SD card
1648 but SD card is not present*/
1649 fp = fopen(app_mmc_internal_path, "r");
1652 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1656 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1661 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1668 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1670 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1672 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1673 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1675 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1676 return PMINFO_R_ERROR;
1678 *removable = _get_bool_value(info->pkg_info->removable);
1683 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1686 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1688 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1689 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1691 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1692 return PMINFO_R_ERROR;
1694 val = (char *)info->pkg_info->installlocation;
1695 if (strcmp(val, "internal-only") == 0)
1703 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1705 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1707 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1708 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1710 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1711 return PMINFO_R_ERROR;
1713 *preload = _get_bool_value(info->pkg_info->preload);
1718 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1720 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1722 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1723 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1725 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1726 return PMINFO_R_ERROR;
1728 *system = _get_bool_value(info->pkg_info->system);
1733 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1735 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1737 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1738 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1740 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1741 return PMINFO_R_ERROR;
1743 *readonly = _get_bool_value(info->pkg_info->readonly);
1748 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1750 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1752 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1753 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1755 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1756 return PMINFO_R_ERROR;
1758 *update = _get_bool_value(info->pkg_info->update);
1763 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1765 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1768 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1770 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1771 return PMINFO_R_ERROR;
1773 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1778 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1780 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1782 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1783 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1785 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1786 return PMINFO_R_ERROR;
1788 *global = _get_bool_value(info->pkg_info->for_all_users);
1793 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1795 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1798 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1800 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1804 __cleanup_pkginfo(info);
1809 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1811 pkgmgrinfo_filter_x *filter;
1813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1815 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1816 if (filter == NULL) {
1817 _LOGE("Out of Memory!!!");
1818 return PMINFO_R_ERROR;
1826 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1828 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1830 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1833 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1834 g_slist_free(filter->list);
1837 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1844 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1845 const char *property, const int value)
1847 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1851 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1852 pkgmgrinfo_node_x *node;
1854 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1855 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1857 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1858 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1859 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1860 _LOGE("Invalid Integer Property\n");
1861 return PMINFO_R_EINVAL;
1863 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1865 _LOGE("Out of Memory!!!\n");
1866 return PMINFO_R_ERROR;
1868 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1869 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1871 _LOGE("Out of Memory\n");
1873 return PMINFO_R_ERROR;
1877 /*If API is called multiple times for same property, we should override the previous values.
1878 Last value set will be used for filtering.*/
1879 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1881 filter->list = g_slist_delete_link(filter->list, link);
1882 filter->list = g_slist_append(filter->list, (gpointer)node);
1887 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1888 const char *property, const bool value)
1893 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1894 pkgmgrinfo_node_x *node;
1896 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1897 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1899 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1900 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1901 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1902 _LOGE("Invalid Boolean Property\n");
1903 return PMINFO_R_EINVAL;
1905 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1907 _LOGE("Out of Memory!!!\n");
1908 return PMINFO_R_ERROR;
1911 val = strndup("true", 4);
1913 val = strndup("false", 5);
1915 _LOGE("Out of Memory\n");
1917 return PMINFO_R_ERROR;
1921 /*If API is called multiple times for same property, we should override the previous values.
1922 Last value set will be used for filtering.*/
1923 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1925 filter->list = g_slist_delete_link(filter->list, link);
1926 filter->list = g_slist_append(filter->list, (gpointer)node);
1931 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1932 const char *property, const char *value)
1937 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1938 pkgmgrinfo_node_x *node;
1940 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1941 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1942 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1944 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1945 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1946 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1947 _LOGE("Invalid String Property\n");
1948 return PMINFO_R_EINVAL;
1950 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1952 _LOGE("Out of Memory!!!\n");
1953 return PMINFO_R_ERROR;
1955 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1956 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1957 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1958 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1959 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1960 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1961 else if (strcmp(value, "installed_internal") == 0)
1962 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1963 else if (strcmp(value, "installed_external") == 0)
1964 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1966 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1968 _LOGE("Out of Memory\n");
1970 return PMINFO_R_ERROR;
1974 /*If API is called multiple times for same property, we should override the previous values.
1975 Last value set will be used for filtering.*/
1976 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1978 filter->list = g_slist_delete_link(filter->list, link);
1979 filter->list = g_slist_append(filter->list, (gpointer)node);
1984 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1988 GHashTable *list = NULL;
1990 if (handle == NULL || count == NULL) {
1991 _LOGE("invalid parameter");
1992 return PMINFO_R_EINVAL;
1995 locale = _get_system_locale();
1997 return PMINFO_R_ERROR;
1999 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
2003 return PMINFO_R_ERROR;
2006 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
2007 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
2008 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
2009 if (ret != PMINFO_R_OK) {
2011 g_hash_table_destroy(list);
2012 return PMINFO_R_ERROR;
2016 ret = _pkginfo_get_packages(uid, locale,
2017 (pkgmgrinfo_filter_x *)handle, 0, list);
2018 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
2019 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
2022 if (ret != PMINFO_R_OK) {
2023 g_hash_table_destroy(list);
2025 return PMINFO_R_ERROR;
2028 *count = g_hash_table_size(list);
2030 g_hash_table_destroy(list);
2036 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
2038 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
2041 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
2042 pkgmgrinfo_pkginfo_filter_h handle,
2043 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
2045 if (handle == NULL || pkg_cb == NULL) {
2046 LOGE("invalid parameter");
2047 return PMINFO_R_EINVAL;
2050 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
2051 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
2054 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
2055 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2057 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2060 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2061 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2064 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2066 privilege_x *privilege;
2067 appdefined_privilege_x *appdefined_privilege;
2069 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2071 if (info->pkg_info == NULL)
2072 return PMINFO_R_ERROR;
2074 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2075 privilege = (privilege_x *)tmp->data;
2076 if (privilege == NULL)
2078 ret = privilege_func(privilege->value, user_data);
2083 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2085 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
2086 if (appdefined_privilege == NULL)
2088 ret = privilege_func(appdefined_privilege->value, user_data);
2095 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
2096 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
2098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2099 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
2100 "Callback function is NULL");
2104 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2106 if (info->pkg_info == NULL)
2107 return PMINFO_R_ERROR;
2109 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
2110 plugin = (plugin_x *)tmp->data;
2113 ret = plugin_func(plugin->pkgid, plugin->appid,
2114 plugin->plugin_type, plugin->plugin_name, user_data);
2122 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
2123 pkgmgrinfo_pkginfo_h handle,
2124 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
2127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2128 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
2129 "Callback function is NULL");
2131 appdefined_privilege_x *privilege;
2133 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2135 if (info->pkg_info == NULL)
2136 return PMINFO_R_ERROR;
2138 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2140 privilege = (appdefined_privilege_x *)tmp->data;
2141 if (privilege == NULL)
2143 ret = privilege_func(privilege->value, privilege->license,
2151 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
2152 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2156 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2158 dependency_x *dependency;
2160 if (handle == NULL || dependency_cb == NULL) {
2161 LOGE("invalid parameter");
2162 return PMINFO_R_EINVAL;
2165 if (info->pkg_info == NULL)
2166 return PMINFO_R_ERROR;
2168 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
2169 dependency = (dependency_x *)tmp->data;
2170 if (dependency == NULL)
2172 ret = dependency_cb(info->pkg_info->package,
2173 dependency->depends_on, dependency->type,
2174 dependency->required_version, user_data);
2189 static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue,
2190 GHashTable **table, GList **pkg_list)
2192 static const char query[] =
2193 "SELECT package, depends_on, type, required_version "
2194 "FROM package_dependency_info WHERE depends_on=?";
2197 struct depends_on *req;
2199 /* already checked */
2200 if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
2203 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2204 if (ret != SQLITE_OK) {
2205 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2206 return PMINFO_R_ERROR;
2209 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
2210 if (ret != SQLITE_OK) {
2211 LOGE("bind failed: %s", sqlite3_errmsg(db));
2212 sqlite3_finalize(stmt);
2213 return PMINFO_R_ERROR;
2216 while (sqlite3_step(stmt) == SQLITE_ROW) {
2217 req = calloc(1, sizeof(struct depends_on));
2219 LOGE("out of memory");
2220 sqlite3_finalize(stmt);
2221 return PMINFO_R_ERROR;
2223 _save_column_str(stmt, 0, &req->from);
2224 _save_column_str(stmt, 1, &req->to);
2225 _save_column_str(stmt, 2, &req->type);
2226 _save_column_str(stmt, 3, &req->version);
2228 *pkg_list = g_list_append(*pkg_list, req);
2229 g_queue_push_tail(*queue, strdup(req->from));
2232 sqlite3_finalize(stmt);
2237 static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid,
2247 dbpath = getUserPkgParserDBPathUID(uid);
2249 return PMINFO_R_ERROR;
2251 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2252 if (ret != SQLITE_OK) {
2253 LOGD("failed to open db(%s): %d", dbpath, ret);
2255 return PMINFO_R_ERROR;
2259 queue = g_queue_new();
2260 if (queue == NULL) {
2261 LOGE("out of memory");
2262 sqlite3_close_v2(db);
2263 return PMINFO_R_ERROR;
2266 table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
2268 g_queue_push_tail(queue, strdup(pkgid));
2269 while (!g_queue_is_empty(queue)) {
2270 item = g_queue_pop_head(queue);
2271 ret = _get_depends_on(db, item, &queue, &table, pkg_list);
2273 if (ret != PMINFO_R_OK) {
2274 LOGE("failed to get pkgs depends on %s", pkgid);
2275 g_hash_table_destroy(table);
2276 g_queue_free_full(queue, free);
2277 sqlite3_close_v2(db);
2278 return PMINFO_R_ERROR;
2282 g_hash_table_destroy(table);
2283 g_queue_free_full(queue, free);
2284 sqlite3_close_v2(db);
2289 static void __free_depends_on(gpointer data)
2291 struct depends_on *dep = (struct depends_on *)data;
2300 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
2301 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2305 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2306 GList *pkg_list = NULL;
2308 struct depends_on *dep;
2310 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
2311 LOGE("invalid parameter");
2312 return PMINFO_R_EINVAL;
2315 ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package,
2317 if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
2318 ret = _pkginfo_foreach_depends_on(GLOBAL_USER,
2319 info->pkg_info->package, &pkg_list);
2321 if (ret != PMINFO_R_OK) {
2322 g_list_free_full(pkg_list, __free_depends_on);
2326 for (l = pkg_list; l != NULL; l = l->next) {
2327 dep = (struct depends_on *)l->data;
2328 ret = dependency_cb(dep->from, dep->to, dep->type, dep->version,
2334 g_list_free_full(pkg_list, __free_depends_on);
2339 int __compare_package_version(const char *version, int *major,
2340 int *minor, int *macro, int *nano)
2342 char *version_temp = NULL;
2343 char *major_str = NULL;
2344 char *minor_str = NULL;
2345 char *macro_str = NULL;
2346 char *nano_str = NULL;
2347 char *save_str = NULL;
2349 if (version == NULL || major == NULL || minor == NULL ||
2350 macro == NULL || nano == NULL) {
2351 return PMINFO_R_EINVAL;
2354 version_temp = strdup(version);
2355 if (version_temp == NULL) {
2356 LOGE("Out of memory");
2357 return PMINFO_R_ERROR;
2360 major_str = strtok_r(version_temp, ".", &save_str);
2361 if (major_str == NULL) {
2362 _LOGE("major version is NULL");
2364 return PMINFO_R_ERROR;
2367 minor_str = strtok_r(NULL, ".", &save_str);
2368 if (minor_str == NULL) {
2369 _LOGE("minor version is NULL");
2371 return PMINFO_R_ERROR;
2374 *major = atoi(major_str);
2375 *minor = atoi(minor_str);
2378 macro_str = strtok_r(NULL, ".", &save_str);
2379 if (macro_str == NULL) {
2380 _LOGD("macro version is NULL");
2382 *macro = atoi(macro_str);
2383 nano_str = strtok_r(NULL, ".", &save_str);
2385 *nano = atoi(nano_str);
2386 _LOGD("nano version exists");
2389 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2390 " macro = [%d], nano = [%d]", version, *major,
2391 *minor, *macro, *nano);
2398 API int pkgmgrinfo_compare_package_version(const char *current_version,
2399 const char *target_version,
2400 pkgmgrinfo_version_compare_type *res)
2403 int current_version_major = 0;
2404 int current_version_minor = 0;
2405 int current_version_macro = 0;
2406 int current_version_nano = 0;
2407 int target_version_major = 0;
2408 int target_version_minor = 0;
2409 int target_version_macro = 0;
2410 int target_version_nano = 0;
2412 if (current_version == NULL || target_version == NULL ||
2414 _LOGE("Invalid parameter");
2415 return PMINFO_R_EINVAL;
2418 ret = __compare_package_version(target_version,
2419 &target_version_major, &target_version_minor,
2420 &target_version_macro, &target_version_nano);
2422 _LOGE("Failed to compare target version(%d)", ret);
2423 return PMINFO_R_ERROR;
2426 ret = __compare_package_version(current_version,
2427 ¤t_version_major, ¤t_version_minor,
2428 ¤t_version_macro, ¤t_version_nano);
2430 _LOGE("Failed to compare current version(%d)", ret);
2431 return PMINFO_R_ERROR;
2434 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2435 target_version_minor, target_version_macro,
2436 target_version_nano, current_version_major,
2437 current_version_minor, current_version_macro,
2438 target_version_nano);
2440 if (target_version_major > current_version_major)
2441 *res = PMINFO_VERSION_NEW;
2442 else if (target_version_major < current_version_major)
2443 *res = PMINFO_VERSION_OLD;
2444 else if (target_version_minor > current_version_minor)
2445 *res = PMINFO_VERSION_NEW;
2446 else if (target_version_minor < current_version_minor)
2447 *res = PMINFO_VERSION_OLD;
2448 else if (target_version_macro > current_version_macro)
2449 *res = PMINFO_VERSION_NEW;
2450 else if (target_version_macro < current_version_macro)
2451 *res = PMINFO_VERSION_OLD;
2452 else if (target_version_nano > current_version_nano)
2453 *res = PMINFO_VERSION_NEW;
2454 else if (target_version_nano < current_version_nano)
2455 *res = PMINFO_VERSION_OLD;
2457 *res = PMINFO_VERSION_SAME;