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_raw[] =
315 "SELECT DISTINCT depends_on, type, required_version "
316 "FROM package_dependency_info WHERE package=%Q";
320 dependency_x *dependency;
322 query = sqlite3_mprintf(query_raw, pkgid);
324 LOGE("out of memory");
325 return PMINFO_R_ERROR;
328 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
330 if (ret != SQLITE_OK) {
331 LOGE("prepare failed: %s", sqlite3_errmsg(db));
332 return PMINFO_R_ERROR;
335 while (sqlite3_step(stmt) == SQLITE_ROW) {
336 dependency = calloc(1, sizeof(dependency_x));
338 LOGE("failed to alloc memory");
339 sqlite3_finalize(stmt);
340 return PMINFO_R_ERROR;
342 _save_column_str(stmt, 0, &dependency->depends_on);
343 _save_column_str(stmt, 1, &dependency->type);
344 _save_column_str(stmt, 2, &dependency->required_version);
345 *dependencies = g_list_append(*dependencies,
346 (gpointer)dependency);
349 sqlite3_finalize(stmt);
354 static const char join_localized_info[] =
355 " LEFT OUTER JOIN package_localized_info"
356 " ON pi.package=package_localized_info.package"
357 " AND package_localized_info.package_locale=?";
358 static const char join_privilege_info[] =
359 " LEFT OUTER JOIN package_privilege_info"
360 " ON pi.package=package_privilege_info.package";
362 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
363 const char *locale, uid_t uid, char **query, GList **bind_params)
366 char buf[MAX_QUERY_LEN] = { '\0' };
367 char buf2[MAX_QUERY_LEN] = { '\0' };
368 char *condition = NULL;
374 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
375 for (list = filter->list; list; list = list->next) {
376 joined |= __get_filter_condition(list->data, uid, &condition,
378 if (condition == NULL)
381 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
383 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
388 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
389 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
390 *bind_params = g_list_append(*bind_params, strdup(locale));
392 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
393 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
394 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
396 *query = strdup(buf2);
398 return PMINFO_R_ERROR;
403 static void __free_packages(gpointer data)
405 pkgmgrinfo_basic_free_package((package_x *)data);
408 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
415 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
422 static int __bind_params(sqlite3_stmt *stmt, GList *params)
424 GList *tmp_list = NULL;
428 if (stmt == NULL || params == NULL)
429 return PMINFO_R_EINVAL;
433 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
434 if (ret != SQLITE_OK)
435 return PMINFO_R_ERROR;
436 tmp_list = tmp_list->next;
442 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
444 GSList *tmp_list = NULL;
445 pkgmgrinfo_node_x *tmp_node = NULL;
448 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
449 for (tmp_list = tmp_filter->list; tmp_list != NULL;
450 tmp_list = g_slist_next(tmp_list)) {
451 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
452 if (property == tmp_node->prop) {
453 if (strcmp(tmp_node->value, "true") == 0)
462 static int _pkginfo_get_packages(uid_t uid, const char *locale,
463 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
465 static const char query_raw[] =
466 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
467 static const char query_basic[] =
468 ", pi.package_version, pi.install_location, "
469 "pi.package_removable, pi.package_preload, pi.package_readonly, "
470 "pi.package_update, pi.package_appsetting, pi.package_system, "
471 "pi.package_type, pi.package_size, pi.installed_time, "
472 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
473 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
474 "pi.package_support_disable, pi.package_tep_name, "
475 "pi.package_zip_mount_file, pi.package_support_mode";
476 static const char query_author[] =
477 ", pi.author_name, pi.author_email, pi.author_href";
478 static const char query_label[] =
480 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
481 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
482 static const char query_icon[] =
484 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
485 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
486 static const char query_description[] =
488 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
489 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
490 static const char query_from_clause[] = " FROM package_info as pi";
491 int ret = PMINFO_R_ERROR;
494 char *tmp_record = NULL;
495 char *constraints = NULL;
496 char query[MAX_QUERY_LEN] = { '\0' };
497 package_x *info = NULL;
498 author_x *author = NULL;
499 GList *bind_params = NULL;
501 sqlite3_stmt *stmt = NULL;
502 pkgmgrinfo_filter_x *tmp_filter = NULL;
503 bool is_check_storage = true;
504 const uid_t global_user_uid = GLOBAL_USER;
506 dbpath = getUserPkgParserDBPathUID(uid);
508 return PMINFO_R_ERROR;
510 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
511 if (ret != SQLITE_OK) {
512 _LOGD("failed to open db(%s): %d", dbpath, ret);
514 return PMINFO_R_ERROR;
518 if (filter != NULL) {
521 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
522 if (ret != PMINFO_R_OK) {
523 _LOGE("Failed to create filter");
524 return PMINFO_R_ERROR;
528 is_check_storage = __check_package_storage_status(tmp_filter);
530 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
531 if (flag & PMINFO_APPINFO_GET_BASICINFO)
532 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
533 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
534 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
535 if (flag & PMINFO_PKGINFO_GET_LABEL) {
536 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
537 bind_params = g_list_append(bind_params, strdup(locale));
539 if (flag & PMINFO_PKGINFO_GET_ICON) {
540 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
541 bind_params = g_list_append(bind_params, strdup(locale));
543 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
544 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
545 bind_params = g_list_append(bind_params, strdup(locale));
548 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
550 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
551 if (ret != PMINFO_R_OK) {
552 LOGE("Failed to get WHERE clause");
557 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
559 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
560 if (ret != SQLITE_OK) {
561 LOGE("prepare failed: %s", sqlite3_errmsg(db));
562 ret = PMINFO_R_ERROR;
566 ret = __bind_params(stmt, bind_params);
567 if (ret != SQLITE_OK) {
568 LOGE("Failed to bind parameters");
572 while (sqlite3_step(stmt) == SQLITE_ROW) {
573 info = calloc(1, sizeof(package_x));
575 LOGE("out of memory");
576 ret = PMINFO_R_ERROR;
580 _save_column_str(stmt, idx++, &info->package);
581 _save_column_str(stmt, idx++, &info->installed_storage);
582 _save_column_str(stmt, idx++, &info->external_path);
584 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
585 _save_column_str(stmt, idx++, &info->version);
586 _save_column_str(stmt, idx++, &info->installlocation);
587 _save_column_str(stmt, idx++, &info->removable);
588 _save_column_str(stmt, idx++, &info->preload);
589 _save_column_str(stmt, idx++, &info->readonly);
590 _save_column_str(stmt, idx++, &info->update);
591 _save_column_str(stmt, idx++, &info->appsetting);
592 _save_column_str(stmt, idx++, &info->system);
593 _save_column_str(stmt, idx++, &info->type);
594 _save_column_str(stmt, idx++, &info->package_size);
595 _save_column_str(stmt, idx++, &info->installed_time);
596 _save_column_str(stmt, idx++, &info->storeclient_id);
597 _save_column_str(stmt, idx++, &info->mainapp_id);
598 _save_column_str(stmt, idx++, &info->package_url);
599 _save_column_str(stmt, idx++, &info->root_path);
600 _save_column_str(stmt, idx++, &info->csc_path);
601 _save_column_str(stmt, idx++, &info->nodisplay_setting);
602 _save_column_str(stmt, idx++, &info->api_version);
603 _save_column_str(stmt, idx++, &info->support_disable);
604 _save_column_str(stmt, idx++, &info->tep_name);
605 _save_column_str(stmt, idx++, &info->zip_mount_file);
606 _save_column_str(stmt, idx++, &info->support_mode);
609 info->for_all_users =
610 strdup((uid != global_user_uid) ? "false" : "true");
612 if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) {
613 ret = PMINFO_R_ERROR;
617 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
618 /* TODO : author should be retrieved at package_localized_info */
619 author = calloc(1, sizeof(author_x));
620 if (author == NULL) {
621 ret = PMINFO_R_ERROR;
624 _save_column_str(stmt, idx++, &author->text);
625 _save_column_str(stmt, idx++, &author->email);
626 _save_column_str(stmt, idx++, &author->href);
627 info->author = g_list_append(info->author, author);
630 if (flag & PMINFO_PKGINFO_GET_LABEL) {
632 _save_column_str(stmt, idx++, &tmp_record);
634 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
635 ret = PMINFO_R_ERROR;
640 if (flag & PMINFO_PKGINFO_GET_ICON) {
642 _save_column_str(stmt, idx++, &tmp_record);
643 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
644 ret = PMINFO_R_ERROR;
649 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
651 _save_column_str(stmt, idx++, &tmp_record);
652 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
653 &info->description)) {
654 ret = PMINFO_R_ERROR;
659 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
660 if (_pkginfo_get_privilege(db, info->package,
661 &info->privileges)) {
662 ret = PMINFO_R_ERROR;
667 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
668 if (_pkginfo_get_appdefined_privilege(db, info->package,
669 &info->appdefined_privileges)) {
670 ret = PMINFO_R_ERROR;
675 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
676 if (_pkginfo_get_dependency(db, info->package,
677 &info->dependencies)) {
678 ret = PMINFO_R_ERROR;
683 if (is_check_storage &&
684 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
685 ret = PMINFO_R_ERROR;
686 pkgmgrinfo_basic_free_package(info);
691 g_hash_table_insert(packages, (gpointer)info->package,
698 sqlite3_finalize(stmt);
699 sqlite3_close_v2(db);
704 if (ret != PMINFO_R_OK && info != NULL)
705 pkgmgrinfo_basic_free_package(info);
708 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
710 g_list_free_full(bind_params, free);
715 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
716 pkgmgrinfo_filter_x *filter, int flag,
717 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
722 pkgmgr_pkginfo_x info;
723 pkgmgrinfo_filter_x *tmp_filter = NULL;
728 locale = _get_system_locale();
730 return PMINFO_R_ERROR;
732 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
736 return PMINFO_R_ERROR;
739 if (filter != NULL) {
740 tmp_filter = (pkgmgrinfo_filter_x *)filter;
742 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
743 if (ret != PMINFO_R_OK) {
744 _LOGE("Failed to create filter");
745 g_hash_table_destroy(list);
747 return PMINFO_R_ERROR;
751 if (__check_disable_filter_exist(tmp_filter) == false) {
752 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
753 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
754 if (ret != PMINFO_R_OK) {
755 _LOGE("Failed to add filter");
756 g_hash_table_destroy(list);
759 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
760 return PMINFO_R_ERROR;
764 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
765 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
766 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
767 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
768 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
770 if (ret != PMINFO_R_OK) {
771 g_hash_table_destroy(list);
774 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
775 return PMINFO_R_ERROR;
778 g_hash_table_iter_init(&iter, list);
779 while (g_hash_table_iter_next(&iter, NULL, &value)) {
780 pkg = (package_x *)value;
783 info.locale = locale;
784 if (pkg_list_cb(&info, user_data) < 0)
788 g_hash_table_destroy(list);
792 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
797 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
798 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
803 pkgmgr_pkginfo_x *info;
805 if (pkgid == NULL || filter == NULL || handle == NULL) {
806 LOGE("invalid parameter");
807 return PMINFO_R_EINVAL;
810 locale = _get_system_locale();
812 return PMINFO_R_ERROR;
814 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
818 return PMINFO_R_ERROR;
821 ret = _pkginfo_get_packages(uid, locale, filter,
822 PMINFO_PKGINFO_GET_ALL, list);
823 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
824 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
825 PMINFO_PKGINFO_GET_ALL, list);
827 if (ret != PMINFO_R_OK) {
828 g_hash_table_destroy(list);
833 if (!g_hash_table_size(list)) {
834 _LOGD("pkginfo for [%s] is not existed for user [%d]",
836 g_hash_table_destroy(list);
838 return PMINFO_R_ENOENT;
841 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
843 _LOGE("out of memory");
844 g_hash_table_destroy(list);
846 return PMINFO_R_ERROR;
850 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
851 info->locale = locale;
853 /* just free list only */
854 g_hash_table_steal(list, (gconstpointer)pkgid);
855 g_hash_table_destroy(list);
862 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
863 pkgmgrinfo_pkginfo_h *handle)
866 pkgmgrinfo_pkginfo_filter_h filter;
868 if (pkgid == NULL || handle == NULL) {
869 LOGE("invalid parameter");
870 return PMINFO_R_EINVAL;
873 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
874 if (ret != PMINFO_R_OK)
877 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
878 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
879 if (ret != PMINFO_R_OK) {
880 pkgmgrinfo_pkginfo_filter_destroy(filter);
881 return PMINFO_R_ERROR;
884 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
885 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
886 if (ret != PMINFO_R_OK) {
887 pkgmgrinfo_pkginfo_filter_destroy(filter);
888 return PMINFO_R_ERROR;
891 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
892 pkgmgrinfo_pkginfo_filter_destroy(filter);
897 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
898 pkgmgrinfo_pkginfo_h *handle)
900 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
903 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
904 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
909 pkgmgrinfo_pkginfo_filter_h filter;
910 pkgmgr_pkginfo_x *info;
912 if (pkgid == NULL || handle == NULL) {
913 LOGE("invalid parameter");
914 return PMINFO_R_EINVAL;
917 locale = _get_system_locale();
919 return PMINFO_R_ERROR;
921 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
922 if (ret != PMINFO_R_OK) {
927 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
928 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
929 if (ret != PMINFO_R_OK) {
930 pkgmgrinfo_pkginfo_filter_destroy(filter);
932 return PMINFO_R_ERROR;
935 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
936 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
937 if (ret != PMINFO_R_OK) {
938 pkgmgrinfo_pkginfo_filter_destroy(filter);
940 return PMINFO_R_ERROR;
943 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
946 pkgmgrinfo_pkginfo_filter_destroy(filter);
948 return PMINFO_R_ERROR;
951 ret = _pkginfo_get_packages(uid, locale, filter,
952 PMINFO_PKGINFO_GET_ALL, list);
953 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
954 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
955 PMINFO_PKGINFO_GET_ALL, list);
957 pkgmgrinfo_pkginfo_filter_destroy(filter);
958 if (ret != PMINFO_R_OK) {
959 g_hash_table_destroy(list);
964 if (!g_hash_table_size(list)) {
965 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
967 g_hash_table_destroy(list);
969 return PMINFO_R_ENOENT;
972 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
974 _LOGE("out of memory");
975 g_hash_table_destroy(list);
977 return PMINFO_R_ERROR;
981 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
982 info->locale = locale;
984 /* just free list only */
985 g_hash_table_steal(list, (gconstpointer)pkgid);
986 g_hash_table_destroy(list);
993 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
994 pkgmgrinfo_pkginfo_h *handle)
998 pkgmgrinfo_pkginfo_filter_h filter;
1000 if (pkgid == NULL || handle == NULL) {
1001 LOGE("invalid parameter");
1002 return PMINFO_R_EINVAL;
1005 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1006 if (ret != PMINFO_R_OK)
1009 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
1010 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
1011 if (ret != PMINFO_R_OK) {
1012 pkgmgrinfo_pkginfo_filter_destroy(filter);
1013 return PMINFO_R_ERROR;
1016 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1017 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
1018 if (ret != PMINFO_R_OK) {
1019 pkgmgrinfo_pkginfo_filter_destroy(filter);
1020 return PMINFO_R_ERROR;
1023 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
1024 pkgmgrinfo_pkginfo_filter_destroy(filter);
1029 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
1030 pkgmgrinfo_pkginfo_h *handle)
1032 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
1036 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
1037 pkgmgrinfo_pkginfo_h *handle)
1039 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
1042 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1043 int flag, void *user_data, uid_t uid)
1046 pkgmgrinfo_pkginfo_filter_h filter;
1048 if (pkg_list_cb == NULL) {
1049 LOGE("invalid parameter");
1050 return PMINFO_R_EINVAL;
1053 /* create an empty filter */
1054 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1055 if (ret != PMINFO_R_OK)
1058 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
1059 pkg_list_cb, user_data);
1061 pkgmgrinfo_pkginfo_filter_destroy(filter);
1066 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1067 int flag, void *user_data)
1069 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
1070 user_data, _getuid());
1073 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1074 void *user_data, uid_t uid)
1077 pkgmgrinfo_pkginfo_filter_h filter;
1079 if (pkg_list_cb == NULL) {
1080 LOGE("invalid parameter");
1081 return PMINFO_R_EINVAL;
1084 /* create an empty filter */
1085 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1086 if (ret != PMINFO_R_OK)
1089 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1090 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1092 pkgmgrinfo_pkginfo_filter_destroy(filter);
1097 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1100 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1104 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1105 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1108 pkgmgrinfo_pkginfo_filter_h filter;
1110 if (pkg_list_cb == NULL) {
1111 LOGE("invalid parameter");
1112 return PMINFO_R_EINVAL;
1115 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1116 if (ret != PMINFO_R_OK)
1119 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1120 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1121 if (ret != PMINFO_R_OK) {
1122 pkgmgrinfo_pkginfo_filter_destroy(filter);
1123 return PMINFO_R_ERROR;
1126 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1127 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1129 pkgmgrinfo_pkginfo_filter_destroy(filter);
1134 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1137 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1141 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1143 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1145 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1146 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1148 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1149 return PMINFO_R_ERROR;
1151 *pkg_name = (char *)info->pkg_info->package;
1156 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1158 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1161 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1163 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1164 return PMINFO_R_ERROR;
1166 *pkgid = (char *)info->pkg_info->package;
1171 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1173 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1175 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1176 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1178 if (info->pkg_info == NULL)
1179 return PMINFO_R_ERROR;
1181 if (info->pkg_info->type == NULL)
1184 *type = (char *)info->pkg_info->type;
1189 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1191 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1193 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1194 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1196 if (info->pkg_info == NULL)
1197 return PMINFO_R_ERROR;
1199 if (info->pkg_info->version == NULL)
1202 *version = (char *)info->pkg_info->version;
1207 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1209 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1211 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1212 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1214 if (info->pkg_info == NULL)
1215 return PMINFO_R_ERROR;
1217 if (info->pkg_info->api_version == NULL)
1220 *api_version = (char *)info->pkg_info->api_version;
1225 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1227 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1229 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1230 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1232 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1233 return PMINFO_R_ERROR;
1235 *tep_name = (char *)info->pkg_info->tep_name;
1240 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1242 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1244 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1245 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1247 if (info->pkg_info == NULL)
1248 return PMINFO_R_ERROR;
1250 if (info->pkg_info->zip_mount_file == NULL)
1251 *zip_mount_file = "";
1253 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1258 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1260 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1263 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1265 if (info->pkg_info == NULL)
1266 return PMINFO_R_ERROR;
1268 if (info->pkg_info->external_path == NULL)
1269 return PMINFO_R_ENOENT;
1271 *ext_image_path = (char *)info->pkg_info->external_path;
1276 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1279 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1282 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1284 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1285 return PMINFO_R_ERROR;
1287 val = (char *)info->pkg_info->installlocation;
1288 if (strcmp(val, "internal-only") == 0)
1289 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1290 else if (strcmp(val, "prefer-external") == 0)
1291 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1293 *location = PMINFO_INSTALL_LOCATION_AUTO;
1298 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1300 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1303 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1304 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1306 if (info->pkg_info == NULL)
1307 return PMINFO_R_ERROR;
1309 if (info->pkg_info->package_size == NULL) {
1312 _LOGE("out of memory");
1313 return PMINFO_R_ERROR;
1315 info->pkg_info->package_size = temp;
1319 *size = atoi((char *)info->pkg_info->package_size);
1324 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1327 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1329 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1330 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1332 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1333 return PMINFO_R_ERROR;
1335 ptr = (icon_x *)info->pkg_info->icon->data;
1337 return PMINFO_R_ERROR;
1339 /* TODO : should we return empty string if there was no icon? */
1340 if (ptr->text == NULL)
1348 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1351 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1353 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1354 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1356 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1357 return PMINFO_R_ERROR;
1359 ptr = (label_x *)info->pkg_info->label->data;
1361 return PMINFO_R_ERROR;
1363 /* TODO : should we return empty string if there was no label? */
1364 if (ptr->text == NULL)
1372 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1375 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1377 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1378 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1380 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1381 return PMINFO_R_ERROR;
1383 ptr = (description_x *)info->pkg_info->description->data;
1385 return PMINFO_R_ERROR;
1387 if (ptr->text == NULL)
1390 *description = (char *)ptr->text;
1395 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1397 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1400 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1401 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1403 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1404 return PMINFO_R_ERROR;
1406 author = (author_x *)info->pkg_info->author->data;
1408 return PMINFO_R_ERROR;
1410 if (author->text == NULL)
1413 *author_name = (char *)author->text;
1418 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1420 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1423 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1424 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1426 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1427 return PMINFO_R_ERROR;
1429 author = (author_x *)info->pkg_info->author->data;
1431 return PMINFO_R_ERROR;
1433 if (author->email == NULL)
1436 *author_email = (char *)author->email;
1441 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1443 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1446 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1447 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1449 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1450 return PMINFO_R_ERROR;
1452 author = (author_x *)info->pkg_info->author->data;
1454 return PMINFO_R_ERROR;
1456 if (author->href == NULL)
1459 *author_href = (char *)author->href;
1464 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1466 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1469 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1471 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1472 return PMINFO_R_ERROR;
1474 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1475 *storage = PMINFO_INTERNAL_STORAGE;
1476 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1477 *storage = PMINFO_EXTERNAL_STORAGE;
1478 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1479 *storage = PMINFO_EXTENDED_STORAGE;
1481 return PMINFO_R_ERROR;
1486 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1488 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1490 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1491 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1493 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1494 return PMINFO_R_ERROR;
1496 *installed_time = atoi(info->pkg_info->installed_time);
1501 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1503 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1505 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1506 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1508 if (info->pkg_info == NULL)
1509 return PMINFO_R_ERROR;
1511 if (info->pkg_info->storeclient_id == NULL)
1512 *storeclientid = "";
1514 *storeclientid = (char *)info->pkg_info->storeclient_id;
1519 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1521 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1523 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1524 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1526 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1527 return PMINFO_R_ERROR;
1529 *mainappid = (char *)info->pkg_info->mainapp_id;
1534 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1536 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1538 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1539 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1541 if (info->pkg_info == NULL)
1542 return PMINFO_R_ERROR;
1544 if (info->pkg_info->package_url == NULL)
1547 *url = (char *)info->pkg_info->package_url;
1552 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1554 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1556 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1557 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1559 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1560 return PMINFO_R_ERROR;
1562 *path = (char *)info->pkg_info->root_path;
1567 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1569 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1572 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1574 if (info->pkg_info == NULL)
1575 return PMINFO_R_ERROR;
1577 if (info->pkg_info->csc_path == NULL)
1580 *path = (char *)info->pkg_info->csc_path;
1585 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1587 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1588 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1590 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1591 if (info->pkg_info->support_mode)
1592 *support_mode = atoi(info->pkg_info->support_mode);
1599 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1601 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1602 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1604 #if 0 /* smack issue occured, check later */
1606 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1607 if (pkgid == NULL) {
1608 _LOGD("invalid func parameters\n");
1609 return PMINFO_R_ERROR;
1611 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1614 char app_mmc_path[FILENAME_MAX] = { 0, };
1615 char app_dir_path[FILENAME_MAX] = { 0, };
1616 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1617 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1618 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1619 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1621 /*check whether application is in external memory or not */
1622 fp = fopen(app_mmc_path, "r");
1624 _LOGD(" app path in external memory not accesible\n");
1629 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1633 /*check whether application is in internal or not */
1635 _LOGD(" app path in internal memory not accesible\n");
1637 return PMINFO_R_ERROR;
1640 /*check whether the application is installed in SD card
1641 but SD card is not present*/
1642 fp = fopen(app_mmc_internal_path, "r");
1645 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1649 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1654 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1661 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1663 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1665 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1666 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1668 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1669 return PMINFO_R_ERROR;
1671 *removable = _get_bool_value(info->pkg_info->removable);
1676 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1679 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1682 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1684 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1685 return PMINFO_R_ERROR;
1687 val = (char *)info->pkg_info->installlocation;
1688 if (strcmp(val, "internal-only") == 0)
1696 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1698 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1701 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1703 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1704 return PMINFO_R_ERROR;
1706 *preload = _get_bool_value(info->pkg_info->preload);
1711 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1713 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1715 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1716 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1718 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1719 return PMINFO_R_ERROR;
1721 *system = _get_bool_value(info->pkg_info->system);
1726 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1728 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1730 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1731 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1733 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1734 return PMINFO_R_ERROR;
1736 *readonly = _get_bool_value(info->pkg_info->readonly);
1741 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1743 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1746 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1748 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1749 return PMINFO_R_ERROR;
1751 *update = _get_bool_value(info->pkg_info->update);
1756 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1758 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1760 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1761 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1763 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1764 return PMINFO_R_ERROR;
1766 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1771 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1773 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1775 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1776 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1778 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1779 return PMINFO_R_ERROR;
1781 *global = _get_bool_value(info->pkg_info->for_all_users);
1786 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1788 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1791 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1793 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1795 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1797 __cleanup_pkginfo(info);
1802 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1804 pkgmgrinfo_filter_x *filter;
1806 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1808 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1809 if (filter == NULL) {
1810 _LOGE("Out of Memory!!!");
1811 return PMINFO_R_ERROR;
1819 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1821 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1823 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1826 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1827 g_slist_free(filter->list);
1830 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1837 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1838 const char *property, const int value)
1840 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1844 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1845 pkgmgrinfo_node_x *node;
1847 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1848 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1850 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1851 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1852 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1853 _LOGE("Invalid Integer Property\n");
1854 return PMINFO_R_EINVAL;
1856 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1858 _LOGE("Out of Memory!!!\n");
1859 return PMINFO_R_ERROR;
1861 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1862 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1864 _LOGE("Out of Memory\n");
1866 return PMINFO_R_ERROR;
1870 /*If API is called multiple times for same property, we should override the previous values.
1871 Last value set will be used for filtering.*/
1872 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1874 filter->list = g_slist_delete_link(filter->list, link);
1875 filter->list = g_slist_append(filter->list, (gpointer)node);
1880 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1881 const char *property, const bool value)
1886 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1887 pkgmgrinfo_node_x *node;
1889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1890 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1892 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1893 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1894 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1895 _LOGE("Invalid Boolean Property\n");
1896 return PMINFO_R_EINVAL;
1898 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1900 _LOGE("Out of Memory!!!\n");
1901 return PMINFO_R_ERROR;
1904 val = strndup("true", 4);
1906 val = strndup("false", 5);
1908 _LOGE("Out of Memory\n");
1910 return PMINFO_R_ERROR;
1914 /*If API is called multiple times for same property, we should override the previous values.
1915 Last value set will be used for filtering.*/
1916 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1918 filter->list = g_slist_delete_link(filter->list, link);
1919 filter->list = g_slist_append(filter->list, (gpointer)node);
1924 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1925 const char *property, const char *value)
1930 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1931 pkgmgrinfo_node_x *node;
1933 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1934 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1935 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1937 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1938 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1939 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1940 _LOGE("Invalid String Property\n");
1941 return PMINFO_R_EINVAL;
1943 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1945 _LOGE("Out of Memory!!!\n");
1946 return PMINFO_R_ERROR;
1948 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1949 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1950 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1951 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1952 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1953 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1954 else if (strcmp(value, "installed_internal") == 0)
1955 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1956 else if (strcmp(value, "installed_external") == 0)
1957 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1959 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1961 _LOGE("Out of Memory\n");
1963 return PMINFO_R_ERROR;
1967 /*If API is called multiple times for same property, we should override the previous values.
1968 Last value set will be used for filtering.*/
1969 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1971 filter->list = g_slist_delete_link(filter->list, link);
1972 filter->list = g_slist_append(filter->list, (gpointer)node);
1977 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1981 GHashTable *list = NULL;
1983 if (handle == NULL || count == NULL) {
1984 _LOGE("invalid parameter");
1985 return PMINFO_R_EINVAL;
1988 locale = _get_system_locale();
1990 return PMINFO_R_ERROR;
1992 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1996 return PMINFO_R_ERROR;
1999 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
2000 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
2001 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
2002 if (ret != PMINFO_R_OK) {
2004 g_hash_table_destroy(list);
2005 return PMINFO_R_ERROR;
2009 ret = _pkginfo_get_packages(uid, locale,
2010 (pkgmgrinfo_filter_x *)handle, 0, list);
2011 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
2012 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
2015 if (ret != PMINFO_R_OK) {
2016 g_hash_table_destroy(list);
2018 return PMINFO_R_ERROR;
2021 *count = g_hash_table_size(list);
2023 g_hash_table_destroy(list);
2029 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
2031 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
2034 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
2035 pkgmgrinfo_pkginfo_filter_h handle,
2036 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
2038 if (handle == NULL || pkg_cb == NULL) {
2039 LOGE("invalid parameter");
2040 return PMINFO_R_EINVAL;
2043 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
2044 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
2047 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
2048 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
2050 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
2053 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
2054 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2056 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2057 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2059 privilege_x *privilege;
2060 appdefined_privilege_x *appdefined_privilege;
2062 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2064 if (info->pkg_info == NULL)
2065 return PMINFO_R_ERROR;
2067 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
2068 privilege = (privilege_x *)tmp->data;
2069 if (privilege == NULL)
2071 ret = privilege_func(privilege->value, user_data);
2076 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2078 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
2079 if (appdefined_privilege == NULL)
2081 ret = privilege_func(appdefined_privilege->value, user_data);
2088 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
2089 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
2091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2092 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
2093 "Callback function is NULL");
2097 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2099 if (info->pkg_info == NULL)
2100 return PMINFO_R_ERROR;
2102 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
2103 plugin = (plugin_x *)tmp->data;
2106 ret = plugin_func(plugin->pkgid, plugin->appid,
2107 plugin->plugin_type, plugin->plugin_name, user_data);
2115 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
2116 pkgmgrinfo_pkginfo_h handle,
2117 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
2120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2121 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
2122 "Callback function is NULL");
2124 appdefined_privilege_x *privilege;
2126 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2128 if (info->pkg_info == NULL)
2129 return PMINFO_R_ERROR;
2131 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2133 privilege = (appdefined_privilege_x *)tmp->data;
2134 if (privilege == NULL)
2136 ret = privilege_func(privilege->value, privilege->license,
2144 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
2145 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2149 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2151 dependency_x *dependency;
2153 if (handle == NULL || dependency_cb == NULL) {
2154 LOGE("invalid parameter");
2155 return PMINFO_R_EINVAL;
2158 if (info->pkg_info == NULL)
2159 return PMINFO_R_ERROR;
2161 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
2162 dependency = (dependency_x *)tmp->data;
2163 if (dependency == NULL)
2165 ret = dependency_cb(info->pkg_info->package,
2166 dependency->depends_on, dependency->type,
2167 dependency->required_version, user_data);
2182 static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue,
2183 GHashTable **table, GList **pkg_list)
2185 static const char query[] =
2186 "SELECT package, depends_on, type, required_version "
2187 "FROM package_dependency_info WHERE depends_on=?";
2190 struct depends_on *req;
2192 /* already checked */
2193 if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
2196 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2197 if (ret != SQLITE_OK) {
2198 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2199 return PMINFO_R_ERROR;
2202 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
2203 if (ret != SQLITE_OK) {
2204 LOGE("bind failed: %s", sqlite3_errmsg(db));
2205 sqlite3_finalize(stmt);
2206 return PMINFO_R_ERROR;
2209 while (sqlite3_step(stmt) == SQLITE_ROW) {
2210 req = calloc(1, sizeof(struct depends_on));
2212 LOGE("out of memory");
2213 sqlite3_finalize(stmt);
2214 return PMINFO_R_ERROR;
2216 _save_column_str(stmt, 0, &req->from);
2217 _save_column_str(stmt, 1, &req->to);
2218 _save_column_str(stmt, 2, &req->type);
2219 _save_column_str(stmt, 3, &req->version);
2221 *pkg_list = g_list_append(*pkg_list, req);
2222 g_queue_push_tail(*queue, strdup(req->from));
2225 sqlite3_finalize(stmt);
2230 static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid,
2240 dbpath = getUserPkgParserDBPathUID(uid);
2242 return PMINFO_R_ERROR;
2244 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2245 if (ret != SQLITE_OK) {
2246 LOGD("failed to open db(%s): %d", dbpath, ret);
2248 return PMINFO_R_ERROR;
2252 queue = g_queue_new();
2253 if (queue == NULL) {
2254 LOGE("out of memory");
2255 sqlite3_close_v2(db);
2256 return PMINFO_R_ERROR;
2259 table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
2261 g_queue_push_tail(queue, strdup(pkgid));
2262 while (!g_queue_is_empty(queue)) {
2263 item = g_queue_pop_head(queue);
2264 ret = _get_depends_on(db, item, &queue, &table, pkg_list);
2266 if (ret != PMINFO_R_OK) {
2267 LOGE("failed to get pkgs depends on %s", pkgid);
2268 g_hash_table_destroy(table);
2269 g_queue_free_full(queue, free);
2270 sqlite3_close_v2(db);
2271 return PMINFO_R_ERROR;
2275 g_hash_table_destroy(table);
2276 g_queue_free_full(queue, free);
2277 sqlite3_close_v2(db);
2282 static void __free_depends_on(gpointer data)
2284 struct depends_on *dep = (struct depends_on *)data;
2293 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
2294 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
2298 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2299 GList *pkg_list = NULL;
2301 struct depends_on *dep;
2303 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
2304 LOGE("invalid parameter");
2305 return PMINFO_R_EINVAL;
2308 ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package,
2310 if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
2311 ret = _pkginfo_foreach_depends_on(GLOBAL_USER,
2312 info->pkg_info->package, &pkg_list);
2314 if (ret != PMINFO_R_OK) {
2315 g_list_free_full(pkg_list, __free_depends_on);
2319 for (l = pkg_list; l != NULL; l = l->next) {
2320 dep = (struct depends_on *)l->data;
2321 ret = dependency_cb(dep->from, dep->to, dep->type, dep->version,
2327 g_list_free_full(pkg_list, __free_depends_on);
2332 int __compare_package_version(const char *version, int *major,
2333 int *minor, int *macro, int *nano)
2335 char *version_temp = NULL;
2336 char *major_str = NULL;
2337 char *minor_str = NULL;
2338 char *macro_str = NULL;
2339 char *nano_str = NULL;
2340 char *save_str = NULL;
2342 if (version == NULL || major == NULL || minor == NULL ||
2343 macro == NULL || nano == NULL) {
2344 return PMINFO_R_EINVAL;
2347 version_temp = strdup(version);
2348 if (version_temp == NULL) {
2349 LOGE("Out of memory");
2350 return PMINFO_R_ERROR;
2353 major_str = strtok_r(version_temp, ".", &save_str);
2354 if (major_str == NULL) {
2355 _LOGE("major version is NULL");
2357 return PMINFO_R_ERROR;
2360 minor_str = strtok_r(NULL, ".", &save_str);
2361 if (minor_str == NULL) {
2362 _LOGE("minor version is NULL");
2364 return PMINFO_R_ERROR;
2367 *major = atoi(major_str);
2368 *minor = atoi(minor_str);
2371 macro_str = strtok_r(NULL, ".", &save_str);
2372 if (macro_str == NULL) {
2373 _LOGD("macro version is NULL");
2375 *macro = atoi(macro_str);
2376 nano_str = strtok_r(NULL, ".", &save_str);
2378 *nano = atoi(nano_str);
2379 _LOGD("nano version exists");
2382 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2383 " macro = [%d], nano = [%d]", version, *major,
2384 *minor, *macro, *nano);
2391 API int pkgmgrinfo_compare_package_version(const char *current_version,
2392 const char *target_version,
2393 pkgmgrinfo_version_compare_type *res)
2396 int current_version_major = 0;
2397 int current_version_minor = 0;
2398 int current_version_macro = 0;
2399 int current_version_nano = 0;
2400 int target_version_major = 0;
2401 int target_version_minor = 0;
2402 int target_version_macro = 0;
2403 int target_version_nano = 0;
2405 if (current_version == NULL || target_version == NULL ||
2407 _LOGE("Invalid parameter");
2408 return PMINFO_R_EINVAL;
2411 ret = __compare_package_version(target_version,
2412 &target_version_major, &target_version_minor,
2413 &target_version_macro, &target_version_nano);
2415 _LOGE("Failed to compare target version(%d)", ret);
2416 return PMINFO_R_ERROR;
2419 ret = __compare_package_version(current_version,
2420 ¤t_version_major, ¤t_version_minor,
2421 ¤t_version_macro, ¤t_version_nano);
2423 _LOGE("Failed to compare current version(%d)", ret);
2424 return PMINFO_R_ERROR;
2427 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2428 target_version_minor, target_version_macro,
2429 target_version_nano, current_version_major,
2430 current_version_minor, current_version_macro,
2431 target_version_nano);
2433 if (target_version_major > current_version_major)
2434 *res = PMINFO_VERSION_NEW;
2435 else if (target_version_major < current_version_major)
2436 *res = PMINFO_VERSION_OLD;
2437 else if (target_version_minor > current_version_minor)
2438 *res = PMINFO_VERSION_NEW;
2439 else if (target_version_minor < current_version_minor)
2440 *res = PMINFO_VERSION_OLD;
2441 else if (target_version_macro > current_version_macro)
2442 *res = PMINFO_VERSION_NEW;
2443 else if (target_version_macro < current_version_macro)
2444 *res = PMINFO_VERSION_OLD;
2445 else if (target_version_nano > current_version_nano)
2446 *res = PMINFO_VERSION_NEW;
2447 else if (target_version_nano < current_version_nano)
2448 *res = PMINFO_VERSION_OLD;
2450 *res = PMINFO_VERSION_SAME;