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));
256 _save_column_str(stmt, 0, &privilege->value);
257 _save_column_str(stmt, 1, &privilege->type);
258 *privileges = g_list_append(*privileges,
259 (gpointer)privilege);
262 sqlite3_finalize(stmt);
267 static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
270 static const char query_raw[] =
271 "SELECT DISTINCT privilege, license, type FROM "
272 "package_appdefined_privilege_info WHERE package=%Q";
276 appdefined_privilege_x *privilege;
278 query = sqlite3_mprintf(query_raw, pkgid);
280 LOGE("out of memory");
281 return PMINFO_R_ERROR;
284 ret = sqlite3_prepare_v2(db, query, strlen(query),
287 if (ret != SQLITE_OK) {
288 LOGE("prepare failed: %s", sqlite3_errmsg(db));
289 return PMINFO_R_ERROR;
292 while (sqlite3_step(stmt) == SQLITE_ROW) {
293 privilege = calloc(1, sizeof(appdefined_privilege_x));
295 LOGE("failed to alloc memory");
296 sqlite3_finalize(stmt);
297 return PMINFO_R_ERROR;
299 _save_column_str(stmt, 0, &privilege->value);
300 _save_column_str(stmt, 1, &privilege->license);
301 _save_column_str(stmt, 2, &privilege->type);
302 *privileges = g_list_append(*privileges,
303 (gpointer)privilege);
306 sqlite3_finalize(stmt);
311 static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid,
312 GList **dependencies)
314 static const char query[] =
315 "SELECT DISTINCT depends_on, type, required_version "
316 "FROM package_dependency_info WHERE package=?";
319 dependency_x *dependency;
321 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
322 if (ret != SQLITE_OK) {
323 LOGE("prepare failed: %s", sqlite3_errmsg(db));
324 return PMINFO_R_ERROR;
327 while (sqlite3_step(stmt) == SQLITE_ROW) {
328 dependency = calloc(1, sizeof(dependency_x));
330 LOGE("failed to alloc memory");
331 sqlite3_finalize(stmt);
332 return PMINFO_R_ERROR;
334 _save_column_str(stmt, 0, &dependency->depends_on);
335 _save_column_str(stmt, 1, &dependency->type);
336 _save_column_str(stmt, 2, &dependency->required_version);
337 *dependencies = g_list_append(*dependencies,
338 (gpointer)dependency);
341 sqlite3_finalize(stmt);
346 static const char join_localized_info[] =
347 " LEFT OUTER JOIN package_localized_info"
348 " ON pi.package=package_localized_info.package"
349 " AND package_localized_info.package_locale=?";
350 static const char join_privilege_info[] =
351 " LEFT OUTER JOIN package_privilege_info"
352 " ON pi.package=package_privilege_info.package";
354 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
355 const char *locale, uid_t uid, char **query, GList **bind_params)
358 char buf[MAX_QUERY_LEN] = { '\0' };
359 char buf2[MAX_QUERY_LEN] = { '\0' };
360 char *condition = NULL;
366 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
367 for (list = filter->list; list; list = list->next) {
368 joined |= __get_filter_condition(list->data, uid, &condition,
370 if (condition == NULL)
373 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
375 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
380 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
381 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
382 *bind_params = g_list_append(*bind_params, strdup(locale));
384 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
385 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
386 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
388 *query = strdup(buf2);
390 return PMINFO_R_ERROR;
395 static void __free_packages(gpointer data)
397 pkgmgrinfo_basic_free_package((package_x *)data);
400 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
407 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
414 static int __bind_params(sqlite3_stmt *stmt, GList *params)
416 GList *tmp_list = NULL;
420 if (stmt == NULL || params == NULL)
421 return PMINFO_R_EINVAL;
425 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
426 if (ret != SQLITE_OK)
427 return PMINFO_R_ERROR;
428 tmp_list = tmp_list->next;
434 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
436 GSList *tmp_list = NULL;
437 pkgmgrinfo_node_x *tmp_node = NULL;
440 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
441 for (tmp_list = tmp_filter->list; tmp_list != NULL;
442 tmp_list = g_slist_next(tmp_list)) {
443 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
444 if (property == tmp_node->prop) {
445 if (strcmp(tmp_node->value, "true") == 0)
454 static int _pkginfo_get_packages(uid_t uid, const char *locale,
455 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
457 static const char query_raw[] =
458 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
459 static const char query_basic[] =
460 ", pi.package_version, pi.install_location, "
461 "pi.package_removable, pi.package_preload, pi.package_readonly, "
462 "pi.package_update, pi.package_appsetting, pi.package_system, "
463 "pi.package_type, pi.package_size, pi.installed_time, "
464 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
465 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
466 "pi.package_support_disable, pi.package_tep_name, "
467 "pi.package_zip_mount_file, pi.package_support_mode";
468 static const char query_author[] =
469 ", pi.author_name, pi.author_email, pi.author_href";
470 static const char query_label[] =
472 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
473 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
474 static const char query_icon[] =
476 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
477 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
478 static const char query_description[] =
480 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
481 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
482 static const char query_from_clause[] = " FROM package_info as pi";
483 int ret = PMINFO_R_ERROR;
486 char *tmp_record = NULL;
487 char *constraints = NULL;
488 char query[MAX_QUERY_LEN] = { '\0' };
489 package_x *info = NULL;
490 author_x *author = NULL;
491 GList *bind_params = NULL;
493 sqlite3_stmt *stmt = NULL;
494 pkgmgrinfo_filter_x *tmp_filter = NULL;
495 bool is_check_storage = true;
496 const uid_t global_user_uid = GLOBAL_USER;
498 dbpath = getUserPkgParserDBPathUID(uid);
500 return PMINFO_R_ERROR;
502 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
503 if (ret != SQLITE_OK) {
504 _LOGD("failed to open db(%s): %d", dbpath, ret);
506 return PMINFO_R_ERROR;
510 if (filter != NULL) {
513 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
514 if (ret != PMINFO_R_OK) {
515 _LOGE("Failed to create filter");
516 return PMINFO_R_ERROR;
520 is_check_storage = __check_package_storage_status(tmp_filter);
522 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
523 if (flag & PMINFO_APPINFO_GET_BASICINFO)
524 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
525 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
526 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
527 if (flag & PMINFO_PKGINFO_GET_LABEL) {
528 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
529 bind_params = g_list_append(bind_params, strdup(locale));
531 if (flag & PMINFO_PKGINFO_GET_ICON) {
532 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
533 bind_params = g_list_append(bind_params, strdup(locale));
535 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
536 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
537 bind_params = g_list_append(bind_params, strdup(locale));
540 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
542 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
543 if (ret != PMINFO_R_OK) {
544 LOGE("Failed to get WHERE clause");
549 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
551 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
552 if (ret != SQLITE_OK) {
553 LOGE("prepare failed: %s", sqlite3_errmsg(db));
554 ret = PMINFO_R_ERROR;
558 ret = __bind_params(stmt, bind_params);
559 if (ret != SQLITE_OK) {
560 LOGE("Failed to bind parameters");
564 while (sqlite3_step(stmt) == SQLITE_ROW) {
565 info = calloc(1, sizeof(package_x));
567 LOGE("out of memory");
568 ret = PMINFO_R_ERROR;
572 _save_column_str(stmt, idx++, &info->package);
573 _save_column_str(stmt, idx++, &info->installed_storage);
574 _save_column_str(stmt, idx++, &info->external_path);
576 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
577 _save_column_str(stmt, idx++, &info->version);
578 _save_column_str(stmt, idx++, &info->installlocation);
579 _save_column_str(stmt, idx++, &info->removable);
580 _save_column_str(stmt, idx++, &info->preload);
581 _save_column_str(stmt, idx++, &info->readonly);
582 _save_column_str(stmt, idx++, &info->update);
583 _save_column_str(stmt, idx++, &info->appsetting);
584 _save_column_str(stmt, idx++, &info->system);
585 _save_column_str(stmt, idx++, &info->type);
586 _save_column_str(stmt, idx++, &info->package_size);
587 _save_column_str(stmt, idx++, &info->installed_time);
588 _save_column_str(stmt, idx++, &info->storeclient_id);
589 _save_column_str(stmt, idx++, &info->mainapp_id);
590 _save_column_str(stmt, idx++, &info->package_url);
591 _save_column_str(stmt, idx++, &info->root_path);
592 _save_column_str(stmt, idx++, &info->csc_path);
593 _save_column_str(stmt, idx++, &info->nodisplay_setting);
594 _save_column_str(stmt, idx++, &info->api_version);
595 _save_column_str(stmt, idx++, &info->support_disable);
596 _save_column_str(stmt, idx++, &info->tep_name);
597 _save_column_str(stmt, idx++, &info->zip_mount_file);
598 _save_column_str(stmt, idx++, &info->support_mode);
601 info->for_all_users =
602 strdup((uid != global_user_uid) ? "false" : "true");
604 if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) {
605 ret = PMINFO_R_ERROR;
609 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
610 /* TODO : author should be retrieved at package_localized_info */
611 author = calloc(1, sizeof(author_x));
612 if (author == NULL) {
613 ret = PMINFO_R_ERROR;
616 _save_column_str(stmt, idx++, &author->text);
617 _save_column_str(stmt, idx++, &author->email);
618 _save_column_str(stmt, idx++, &author->href);
619 info->author = g_list_append(info->author, author);
622 if (flag & PMINFO_PKGINFO_GET_LABEL) {
624 _save_column_str(stmt, idx++, &tmp_record);
626 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
627 ret = PMINFO_R_ERROR;
632 if (flag & PMINFO_PKGINFO_GET_ICON) {
634 _save_column_str(stmt, idx++, &tmp_record);
635 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
636 ret = PMINFO_R_ERROR;
641 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
643 _save_column_str(stmt, idx++, &tmp_record);
644 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
645 &info->description)) {
646 ret = PMINFO_R_ERROR;
651 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
652 if (_pkginfo_get_privilege(db, info->package,
653 &info->privileges)) {
654 ret = PMINFO_R_ERROR;
659 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
660 if (_pkginfo_get_appdefined_privilege(db, info->package,
661 &info->appdefined_privileges)) {
662 ret = PMINFO_R_ERROR;
667 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
668 if (_pkginfo_get_dependency(db, info->package,
669 &info->dependencies)) {
670 ret = PMINFO_R_ERROR;
675 if (is_check_storage &&
676 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
677 ret = PMINFO_R_ERROR;
678 pkgmgrinfo_basic_free_package(info);
683 g_hash_table_insert(packages, (gpointer)info->package,
690 sqlite3_finalize(stmt);
691 sqlite3_close_v2(db);
696 if (ret != PMINFO_R_OK && info != NULL)
697 pkgmgrinfo_basic_free_package(info);
700 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
702 g_list_free_full(bind_params, free);
707 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
708 pkgmgrinfo_filter_x *filter, int flag,
709 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
714 pkgmgr_pkginfo_x info;
715 pkgmgrinfo_filter_x *tmp_filter = NULL;
720 locale = _get_system_locale();
722 return PMINFO_R_ERROR;
724 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
728 return PMINFO_R_ERROR;
731 if (filter != NULL) {
732 tmp_filter = (pkgmgrinfo_filter_x *)filter;
734 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
735 if (ret != PMINFO_R_OK) {
736 _LOGE("Failed to create filter");
737 g_hash_table_destroy(list);
739 return PMINFO_R_ERROR;
743 if (__check_disable_filter_exist(tmp_filter) == false) {
744 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
745 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
746 if (ret != PMINFO_R_OK) {
747 _LOGE("Failed to add filter");
748 g_hash_table_destroy(list);
751 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
752 return PMINFO_R_ERROR;
756 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
757 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
758 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
759 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
760 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
762 if (ret != PMINFO_R_OK) {
763 g_hash_table_destroy(list);
766 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
767 return PMINFO_R_ERROR;
770 g_hash_table_iter_init(&iter, list);
771 while (g_hash_table_iter_next(&iter, NULL, &value)) {
772 pkg = (package_x *)value;
775 info.locale = locale;
776 if (pkg_list_cb(&info, user_data) < 0)
780 g_hash_table_destroy(list);
784 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
789 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
790 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
795 pkgmgr_pkginfo_x *info;
797 if (pkgid == NULL || filter == NULL || handle == NULL) {
798 LOGE("invalid parameter");
799 return PMINFO_R_EINVAL;
802 locale = _get_system_locale();
804 return PMINFO_R_ERROR;
806 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
810 return PMINFO_R_ERROR;
813 ret = _pkginfo_get_packages(uid, locale, filter,
814 PMINFO_PKGINFO_GET_ALL, list);
815 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
816 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
817 PMINFO_PKGINFO_GET_ALL, list);
819 if (ret != PMINFO_R_OK) {
820 g_hash_table_destroy(list);
825 if (!g_hash_table_size(list)) {
826 _LOGD("pkginfo for [%s] is not existed for user [%d]",
828 g_hash_table_destroy(list);
830 return PMINFO_R_ENOENT;
833 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
835 _LOGE("out of memory");
836 g_hash_table_destroy(list);
838 return PMINFO_R_ERROR;
842 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
843 info->locale = locale;
845 /* just free list only */
846 g_hash_table_steal(list, (gconstpointer)pkgid);
847 g_hash_table_destroy(list);
854 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
855 pkgmgrinfo_pkginfo_h *handle)
858 pkgmgrinfo_pkginfo_filter_h filter;
860 if (pkgid == NULL || handle == NULL) {
861 LOGE("invalid parameter");
862 return PMINFO_R_EINVAL;
865 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
866 if (ret != PMINFO_R_OK)
869 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
870 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
871 if (ret != PMINFO_R_OK) {
872 pkgmgrinfo_pkginfo_filter_destroy(filter);
873 return PMINFO_R_ERROR;
876 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
877 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
878 if (ret != PMINFO_R_OK) {
879 pkgmgrinfo_pkginfo_filter_destroy(filter);
880 return PMINFO_R_ERROR;
883 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
884 pkgmgrinfo_pkginfo_filter_destroy(filter);
889 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
890 pkgmgrinfo_pkginfo_h *handle)
892 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
895 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
896 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
901 pkgmgrinfo_pkginfo_filter_h filter;
902 pkgmgr_pkginfo_x *info;
904 if (pkgid == NULL || handle == NULL) {
905 LOGE("invalid parameter");
906 return PMINFO_R_EINVAL;
909 locale = _get_system_locale();
911 return PMINFO_R_ERROR;
913 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
914 if (ret != PMINFO_R_OK) {
919 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
920 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
921 if (ret != PMINFO_R_OK) {
922 pkgmgrinfo_pkginfo_filter_destroy(filter);
924 return PMINFO_R_ERROR;
927 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
928 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
929 if (ret != PMINFO_R_OK) {
930 pkgmgrinfo_pkginfo_filter_destroy(filter);
932 return PMINFO_R_ERROR;
935 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
938 pkgmgrinfo_pkginfo_filter_destroy(filter);
940 return PMINFO_R_ERROR;
943 ret = _pkginfo_get_packages(uid, locale, filter,
944 PMINFO_PKGINFO_GET_ALL, list);
945 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
946 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
947 PMINFO_PKGINFO_GET_ALL, list);
949 pkgmgrinfo_pkginfo_filter_destroy(filter);
950 if (ret != PMINFO_R_OK) {
951 g_hash_table_destroy(list);
956 if (!g_hash_table_size(list)) {
957 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
959 g_hash_table_destroy(list);
961 return PMINFO_R_ENOENT;
964 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
966 _LOGE("out of memory");
967 g_hash_table_destroy(list);
969 return PMINFO_R_ERROR;
973 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
974 info->locale = locale;
976 /* just free list only */
977 g_hash_table_steal(list, (gconstpointer)pkgid);
978 g_hash_table_destroy(list);
985 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
986 pkgmgrinfo_pkginfo_h *handle)
990 pkgmgrinfo_pkginfo_filter_h filter;
992 if (pkgid == NULL || handle == NULL) {
993 LOGE("invalid parameter");
994 return PMINFO_R_EINVAL;
997 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
998 if (ret != PMINFO_R_OK)
1001 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
1002 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
1003 if (ret != PMINFO_R_OK) {
1004 pkgmgrinfo_pkginfo_filter_destroy(filter);
1005 return PMINFO_R_ERROR;
1008 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1009 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
1010 if (ret != PMINFO_R_OK) {
1011 pkgmgrinfo_pkginfo_filter_destroy(filter);
1012 return PMINFO_R_ERROR;
1015 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
1016 pkgmgrinfo_pkginfo_filter_destroy(filter);
1021 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
1022 pkgmgrinfo_pkginfo_h *handle)
1024 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
1028 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
1029 pkgmgrinfo_pkginfo_h *handle)
1031 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
1034 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1035 int flag, void *user_data, uid_t uid)
1038 pkgmgrinfo_pkginfo_filter_h filter;
1040 if (pkg_list_cb == NULL) {
1041 LOGE("invalid parameter");
1042 return PMINFO_R_EINVAL;
1045 /* create an empty filter */
1046 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1047 if (ret != PMINFO_R_OK)
1050 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
1051 pkg_list_cb, user_data);
1053 pkgmgrinfo_pkginfo_filter_destroy(filter);
1058 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1059 int flag, void *user_data)
1061 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
1062 user_data, _getuid());
1065 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1066 void *user_data, uid_t uid)
1069 pkgmgrinfo_pkginfo_filter_h filter;
1071 if (pkg_list_cb == NULL) {
1072 LOGE("invalid parameter");
1073 return PMINFO_R_EINVAL;
1076 /* create an empty filter */
1077 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1078 if (ret != PMINFO_R_OK)
1081 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1082 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1084 pkgmgrinfo_pkginfo_filter_destroy(filter);
1089 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1092 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1096 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1097 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1100 pkgmgrinfo_pkginfo_filter_h filter;
1102 if (pkg_list_cb == NULL) {
1103 LOGE("invalid parameter");
1104 return PMINFO_R_EINVAL;
1107 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1108 if (ret != PMINFO_R_OK)
1111 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1112 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1113 if (ret != PMINFO_R_OK) {
1114 pkgmgrinfo_pkginfo_filter_destroy(filter);
1115 return PMINFO_R_ERROR;
1118 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1119 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1121 pkgmgrinfo_pkginfo_filter_destroy(filter);
1126 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1129 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1133 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1135 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1137 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1138 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1140 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1141 return PMINFO_R_ERROR;
1143 *pkg_name = (char *)info->pkg_info->package;
1148 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
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(pkgid == 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 *pkgid = (char *)info->pkg_info->package;
1163 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
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(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1170 if (info->pkg_info == NULL)
1171 return PMINFO_R_ERROR;
1173 if (info->pkg_info->type == NULL)
1176 *type = (char *)info->pkg_info->type;
1181 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1183 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1186 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1188 if (info->pkg_info == NULL)
1189 return PMINFO_R_ERROR;
1191 if (info->pkg_info->version == NULL)
1194 *version = (char *)info->pkg_info->version;
1199 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1201 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1204 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1206 if (info->pkg_info == NULL)
1207 return PMINFO_R_ERROR;
1209 if (info->pkg_info->api_version == NULL)
1212 *api_version = (char *)info->pkg_info->api_version;
1217 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1219 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1222 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1224 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1225 return PMINFO_R_ERROR;
1227 *tep_name = (char *)info->pkg_info->tep_name;
1232 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
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(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 if (info->pkg_info == NULL)
1240 return PMINFO_R_ERROR;
1242 if (info->pkg_info->zip_mount_file == NULL)
1243 *zip_mount_file = "";
1245 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1250 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1252 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1254 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1255 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1257 if (info->pkg_info == NULL)
1258 return PMINFO_R_ERROR;
1260 if (info->pkg_info->external_path == NULL)
1261 return PMINFO_R_ENOENT;
1263 *ext_image_path = (char *)info->pkg_info->external_path;
1268 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1271 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1274 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1276 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1277 return PMINFO_R_ERROR;
1279 val = (char *)info->pkg_info->installlocation;
1280 if (strcmp(val, "internal-only") == 0)
1281 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1282 else if (strcmp(val, "prefer-external") == 0)
1283 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1285 *location = PMINFO_INSTALL_LOCATION_AUTO;
1290 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1292 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1296 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1298 if (info->pkg_info == NULL)
1299 return PMINFO_R_ERROR;
1301 if (info->pkg_info->package_size == NULL) {
1304 _LOGE("out of memory");
1305 return PMINFO_R_ERROR;
1307 info->pkg_info->package_size = temp;
1311 *size = atoi((char *)info->pkg_info->package_size);
1316 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1319 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1322 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1324 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1325 return PMINFO_R_ERROR;
1327 ptr = (icon_x *)info->pkg_info->icon->data;
1329 return PMINFO_R_ERROR;
1331 /* TODO : should we return empty string if there was no icon? */
1332 if (ptr->text == NULL)
1340 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1343 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1346 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1348 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1349 return PMINFO_R_ERROR;
1351 ptr = (label_x *)info->pkg_info->label->data;
1353 return PMINFO_R_ERROR;
1355 /* TODO : should we return empty string if there was no label? */
1356 if (ptr->text == NULL)
1364 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1367 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1369 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1370 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1372 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1373 return PMINFO_R_ERROR;
1375 ptr = (description_x *)info->pkg_info->description->data;
1377 return PMINFO_R_ERROR;
1379 if (ptr->text == NULL)
1382 *description = (char *)ptr->text;
1387 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1389 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1393 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1395 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1396 return PMINFO_R_ERROR;
1398 author = (author_x *)info->pkg_info->author->data;
1400 return PMINFO_R_ERROR;
1402 if (author->text == NULL)
1405 *author_name = (char *)author->text;
1410 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1412 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1415 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1416 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1418 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1419 return PMINFO_R_ERROR;
1421 author = (author_x *)info->pkg_info->author->data;
1423 return PMINFO_R_ERROR;
1425 if (author->email == NULL)
1428 *author_email = (char *)author->email;
1433 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1435 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1438 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1439 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1441 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1442 return PMINFO_R_ERROR;
1444 author = (author_x *)info->pkg_info->author->data;
1446 return PMINFO_R_ERROR;
1448 if (author->href == NULL)
1451 *author_href = (char *)author->href;
1456 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1458 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1461 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1463 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1464 return PMINFO_R_ERROR;
1466 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1467 *storage = PMINFO_INTERNAL_STORAGE;
1468 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1469 *storage = PMINFO_EXTERNAL_STORAGE;
1470 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1471 *storage = PMINFO_EXTENDED_STORAGE;
1473 return PMINFO_R_ERROR;
1478 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1480 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1483 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1485 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1486 return PMINFO_R_ERROR;
1488 *installed_time = atoi(info->pkg_info->installed_time);
1493 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
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(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1500 if (info->pkg_info == NULL)
1501 return PMINFO_R_ERROR;
1503 if (info->pkg_info->storeclient_id == NULL)
1504 *storeclientid = "";
1506 *storeclientid = (char *)info->pkg_info->storeclient_id;
1511 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1513 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1515 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1516 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1518 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1519 return PMINFO_R_ERROR;
1521 *mainappid = (char *)info->pkg_info->mainapp_id;
1526 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
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(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1533 if (info->pkg_info == NULL)
1534 return PMINFO_R_ERROR;
1536 if (info->pkg_info->package_url == NULL)
1539 *url = (char *)info->pkg_info->package_url;
1544 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1546 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1548 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1549 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1551 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1552 return PMINFO_R_ERROR;
1554 *path = (char *)info->pkg_info->root_path;
1559 API int pkgmgrinfo_pkginfo_get_csc_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)
1567 return PMINFO_R_ERROR;
1569 if (info->pkg_info->csc_path == NULL)
1572 *path = (char *)info->pkg_info->csc_path;
1577 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1579 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1580 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1582 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1583 if (info->pkg_info->support_mode)
1584 *support_mode = atoi(info->pkg_info->support_mode);
1591 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1593 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1594 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1596 #if 0 /* smack issue occured, check later */
1598 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1599 if (pkgid == NULL) {
1600 _LOGD("invalid func parameters\n");
1601 return PMINFO_R_ERROR;
1603 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1606 char app_mmc_path[FILENAME_MAX] = { 0, };
1607 char app_dir_path[FILENAME_MAX] = { 0, };
1608 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1609 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1610 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1611 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1613 /*check whether application is in external memory or not */
1614 fp = fopen(app_mmc_path, "r");
1616 _LOGD(" app path in external memory not accesible\n");
1621 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1625 /*check whether application is in internal or not */
1627 _LOGD(" app path in internal memory not accesible\n");
1629 return PMINFO_R_ERROR;
1632 /*check whether the application is installed in SD card
1633 but SD card is not present*/
1634 fp = fopen(app_mmc_internal_path, "r");
1637 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1641 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1646 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1653 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1655 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1658 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1660 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1661 return PMINFO_R_ERROR;
1663 *removable = _get_bool_value(info->pkg_info->removable);
1668 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1671 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1674 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1676 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1677 return PMINFO_R_ERROR;
1679 val = (char *)info->pkg_info->installlocation;
1680 if (strcmp(val, "internal-only") == 0)
1688 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1690 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1692 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1693 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1695 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1696 return PMINFO_R_ERROR;
1698 *preload = _get_bool_value(info->pkg_info->preload);
1703 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
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(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1710 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1711 return PMINFO_R_ERROR;
1713 *system = _get_bool_value(info->pkg_info->system);
1718 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
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(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1725 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1726 return PMINFO_R_ERROR;
1728 *readonly = _get_bool_value(info->pkg_info->readonly);
1733 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
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(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1740 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1741 return PMINFO_R_ERROR;
1743 *update = _get_bool_value(info->pkg_info->update);
1748 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
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(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1755 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1756 return PMINFO_R_ERROR;
1758 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1763 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
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(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1770 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1771 return PMINFO_R_ERROR;
1773 *global = _get_bool_value(info->pkg_info->for_all_users);
1778 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1780 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1783 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1785 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1789 __cleanup_pkginfo(info);
1794 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1796 pkgmgrinfo_filter_x *filter;
1798 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1800 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1801 if (filter == NULL) {
1802 _LOGE("Out of Memory!!!");
1803 return PMINFO_R_ERROR;
1811 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1813 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1815 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1818 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1819 g_slist_free(filter->list);
1822 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1829 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1830 const char *property, const int value)
1832 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1836 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1837 pkgmgrinfo_node_x *node;
1839 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1840 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1842 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1843 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1844 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1845 _LOGE("Invalid Integer Property\n");
1846 return PMINFO_R_EINVAL;
1848 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1850 _LOGE("Out of Memory!!!\n");
1851 return PMINFO_R_ERROR;
1853 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1854 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1856 _LOGE("Out of Memory\n");
1858 return PMINFO_R_ERROR;
1862 /*If API is called multiple times for same property, we should override the previous values.
1863 Last value set will be used for filtering.*/
1864 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1866 filter->list = g_slist_delete_link(filter->list, link);
1867 filter->list = g_slist_append(filter->list, (gpointer)node);
1872 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1873 const char *property, const bool value)
1878 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1879 pkgmgrinfo_node_x *node;
1881 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1882 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1884 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1885 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1886 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1887 _LOGE("Invalid Boolean Property\n");
1888 return PMINFO_R_EINVAL;
1890 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1892 _LOGE("Out of Memory!!!\n");
1893 return PMINFO_R_ERROR;
1896 val = strndup("true", 4);
1898 val = strndup("false", 5);
1900 _LOGE("Out of Memory\n");
1902 return PMINFO_R_ERROR;
1906 /*If API is called multiple times for same property, we should override the previous values.
1907 Last value set will be used for filtering.*/
1908 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1910 filter->list = g_slist_delete_link(filter->list, link);
1911 filter->list = g_slist_append(filter->list, (gpointer)node);
1916 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1917 const char *property, const char *value)
1922 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1923 pkgmgrinfo_node_x *node;
1925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1926 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1927 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1929 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1930 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1931 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1932 _LOGE("Invalid String Property\n");
1933 return PMINFO_R_EINVAL;
1935 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1937 _LOGE("Out of Memory!!!\n");
1938 return PMINFO_R_ERROR;
1940 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1941 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1942 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1943 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1944 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1945 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1946 else if (strcmp(value, "installed_internal") == 0)
1947 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1948 else if (strcmp(value, "installed_external") == 0)
1949 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1951 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1953 _LOGE("Out of Memory\n");
1955 return PMINFO_R_ERROR;
1959 /*If API is called multiple times for same property, we should override the previous values.
1960 Last value set will be used for filtering.*/
1961 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1963 filter->list = g_slist_delete_link(filter->list, link);
1964 filter->list = g_slist_append(filter->list, (gpointer)node);
1969 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1973 GHashTable *list = NULL;
1975 if (handle == NULL || count == NULL) {
1976 _LOGE("invalid parameter");
1977 return PMINFO_R_EINVAL;
1980 locale = _get_system_locale();
1982 return PMINFO_R_ERROR;
1984 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1988 return PMINFO_R_ERROR;
1991 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1992 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1993 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1994 if (ret != PMINFO_R_OK) {
1996 g_hash_table_destroy(list);
1997 return PMINFO_R_ERROR;
2001 ret = _pkginfo_get_packages(uid, locale,
2002 (pkgmgrinfo_filter_x *)handle, 0, list);
2003 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
2004 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
2007 if (ret != PMINFO_R_OK) {
2008 g_hash_table_destroy(list);
2010 return PMINFO_R_ERROR;
2013 *count = g_hash_table_size(list);
2015 g_hash_table_destroy(list);
2021 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
2023 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
2026 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
2027 pkgmgrinfo_pkginfo_filter_h handle,
2028 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
2030 if (handle == NULL || pkg_cb == NULL) {
2031 LOGE("invalid parameter");
2032 return PMINFO_R_EINVAL;
2035 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
2036 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
2039 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
2040 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2042 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2045 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2046 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2049 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2051 privilege_x *privilege;
2052 appdefined_privilege_x *appdefined_privilege;
2054 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2056 if (info->pkg_info == NULL)
2057 return PMINFO_R_ERROR;
2059 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2060 privilege = (privilege_x *)tmp->data;
2061 if (privilege == NULL)
2063 ret = privilege_func(privilege->value, user_data);
2068 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2070 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
2071 if (appdefined_privilege == NULL)
2073 ret = privilege_func(appdefined_privilege->value, user_data);
2080 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
2081 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
2083 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2084 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
2085 "Callback function is NULL");
2089 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2091 if (info->pkg_info == NULL)
2092 return PMINFO_R_ERROR;
2094 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
2095 plugin = (plugin_x *)tmp->data;
2098 ret = plugin_func(plugin->pkgid, plugin->appid,
2099 plugin->plugin_type, plugin->plugin_name, user_data);
2107 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
2108 pkgmgrinfo_pkginfo_h handle,
2109 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
2112 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2113 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
2114 "Callback function is NULL");
2116 appdefined_privilege_x *privilege;
2118 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2120 if (info->pkg_info == NULL)
2121 return PMINFO_R_ERROR;
2123 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2125 privilege = (appdefined_privilege_x *)tmp->data;
2126 if (privilege == NULL)
2128 ret = privilege_func(privilege->value, privilege->license,
2136 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
2137 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2141 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2143 dependency_x *dependency;
2145 if (handle == NULL || dependency_cb == NULL) {
2146 LOGE("invalid parameter");
2147 return PMINFO_R_EINVAL;
2150 if (info->pkg_info == NULL)
2151 return PMINFO_R_ERROR;
2153 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
2154 dependency = (dependency_x *)tmp->data;
2155 if (dependency == NULL)
2157 ret = dependency_cb(dependency->depends_on, dependency->type,
2158 dependency->required_version, user_data);
2166 struct required_by {
2172 static int _get_required_by(sqlite3 *db, const char *pkgid, GQueue **queue,
2173 GHashTable **table, GList **pkg_list)
2175 static const char query[] =
2176 "SELECT package, type, required_version "
2177 "FROM package_dependency_info WHERE depends_on=?";
2180 struct required_by *req;
2182 /* already checked */
2183 if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
2186 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2187 if (ret != SQLITE_OK) {
2188 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2189 return PMINFO_R_ERROR;
2192 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
2193 if (ret != SQLITE_OK) {
2194 LOGE("bind failed: %s", sqlite3_errmsg(db));
2195 sqlite3_finalize(stmt);
2196 return PMINFO_R_ERROR;
2199 while (sqlite3_step(stmt) == SQLITE_ROW) {
2200 req = calloc(1, sizeof(struct required_by));
2202 LOGE("out of memory");
2203 sqlite3_finalize(stmt);
2204 return PMINFO_R_ERROR;
2206 _save_column_str(stmt, 0, &req->pkgid);
2207 _save_column_str(stmt, 1, &req->type);
2208 _save_column_str(stmt, 2, &req->version);
2210 *pkg_list = g_list_append(*pkg_list, req);
2211 g_queue_push_tail(*queue, strdup(req->pkgid));
2214 sqlite3_finalize(stmt);
2219 static int _pkginfo_foreach_required_by(uid_t uid, const char *pkgid,
2229 dbpath = getUserPkgParserDBPathUID(uid);
2231 return PMINFO_R_ERROR;
2233 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2234 if (ret != SQLITE_OK) {
2235 LOGD("failed to open db(%s): %d", dbpath, ret);
2237 return PMINFO_R_ERROR;
2241 queue = g_queue_new();
2242 if (queue == NULL) {
2243 LOGE("out of memory");
2244 sqlite3_close_v2(db);
2245 return PMINFO_R_ERROR;
2248 table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
2250 g_queue_push_tail(queue, strdup(pkgid));
2251 while (!g_queue_is_empty(queue)) {
2252 item = g_queue_pop_head(queue);
2253 ret = _get_required_by(db, item, &queue, &table, pkg_list);
2255 if (ret != PMINFO_R_OK) {
2256 LOGE("failed to get required by pkgs");
2257 g_hash_table_destroy(table);
2258 g_queue_free_full(queue, free);
2259 sqlite3_close_v2(db);
2260 return PMINFO_R_ERROR;
2264 g_hash_table_destroy(table);
2265 g_queue_free_full(queue, free);
2266 sqlite3_close_v2(db);
2271 static void __free_required_by(gpointer data)
2273 struct required_by *req = (struct required_by *)data;
2281 API int pkgmgrinfo_pkginfo_foreach_required_by(pkgmgrinfo_pkginfo_h handle,
2282 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2286 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2287 GList *pkg_list = NULL;
2289 struct required_by *req;
2291 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
2292 LOGE("invalid parameter");
2293 return PMINFO_R_EINVAL;
2296 ret = _pkginfo_foreach_required_by(info->uid, info->pkg_info->package,
2298 if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
2299 ret = _pkginfo_foreach_required_by(GLOBAL_USER,
2300 info->pkg_info->package, &pkg_list);
2302 if (ret != PMINFO_R_OK) {
2303 g_list_free_full(pkg_list, __free_required_by);
2307 for (l = pkg_list; l != NULL; l = l->next) {
2308 req = (struct required_by *)l->data;
2309 ret = dependency_cb(req->pkgid, req->type, req->version,
2315 g_list_free_full(pkg_list, __free_required_by);
2320 int __compare_package_version(const char *version, int *major,
2321 int *minor, int *macro, int *nano)
2323 char *version_temp = NULL;
2324 char *major_str = NULL;
2325 char *minor_str = NULL;
2326 char *macro_str = NULL;
2327 char *nano_str = NULL;
2328 char *save_str = NULL;
2330 if (version == NULL || major == NULL || minor == NULL ||
2331 macro == NULL || nano == NULL) {
2332 return PMINFO_R_EINVAL;
2335 version_temp = strdup(version);
2336 if (version_temp == NULL) {
2337 LOGE("Out of memory");
2338 return PMINFO_R_ERROR;
2341 major_str = strtok_r(version_temp, ".", &save_str);
2342 if (major_str == NULL) {
2343 _LOGE("major version is NULL");
2345 return PMINFO_R_ERROR;
2348 minor_str = strtok_r(NULL, ".", &save_str);
2349 if (minor_str == NULL) {
2350 _LOGE("minor version is NULL");
2352 return PMINFO_R_ERROR;
2355 *major = atoi(major_str);
2356 *minor = atoi(minor_str);
2359 macro_str = strtok_r(NULL, ".", &save_str);
2360 if (macro_str == NULL) {
2361 _LOGD("macro version is NULL");
2363 *macro = atoi(macro_str);
2364 nano_str = strtok_r(NULL, ".", &save_str);
2366 *nano = atoi(nano_str);
2367 _LOGD("nano version exists");
2370 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2371 " macro = [%d], nano = [%d]", version, *major,
2372 *minor, *macro, *nano);
2379 API int pkgmgrinfo_compare_package_version(const char *current_version,
2380 const char *target_version,
2381 pkgmgrinfo_version_compare_type *res)
2384 int current_version_major = 0;
2385 int current_version_minor = 0;
2386 int current_version_macro = 0;
2387 int current_version_nano = 0;
2388 int target_version_major = 0;
2389 int target_version_minor = 0;
2390 int target_version_macro = 0;
2391 int target_version_nano = 0;
2393 if (current_version == NULL || target_version == NULL ||
2395 _LOGE("Invalid parameter");
2396 return PMINFO_R_EINVAL;
2399 ret = __compare_package_version(target_version,
2400 &target_version_major, &target_version_minor,
2401 &target_version_macro, &target_version_nano);
2403 _LOGE("Failed to compare target version(%d)", ret);
2404 return PMINFO_R_ERROR;
2407 ret = __compare_package_version(current_version,
2408 ¤t_version_major, ¤t_version_minor,
2409 ¤t_version_macro, ¤t_version_nano);
2411 _LOGE("Failed to compare current version(%d)", ret);
2412 return PMINFO_R_ERROR;
2415 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2416 target_version_minor, target_version_macro,
2417 target_version_nano, current_version_major,
2418 current_version_minor, current_version_macro,
2419 target_version_nano);
2421 if (target_version_major > current_version_major)
2422 *res = PMINFO_VERSION_NEW;
2423 else if (target_version_major < current_version_major)
2424 *res = PMINFO_VERSION_OLD;
2425 else if (target_version_minor > current_version_minor)
2426 *res = PMINFO_VERSION_NEW;
2427 else if (target_version_minor < current_version_minor)
2428 *res = PMINFO_VERSION_OLD;
2429 else if (target_version_macro > current_version_macro)
2430 *res = PMINFO_VERSION_NEW;
2431 else if (target_version_macro < current_version_macro)
2432 *res = PMINFO_VERSION_OLD;
2433 else if (target_version_nano > current_version_nano)
2434 *res = PMINFO_VERSION_NEW;
2435 else if (target_version_nano < current_version_nano)
2436 *res = PMINFO_VERSION_OLD;
2438 *res = PMINFO_VERSION_SAME;