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>
37 #include "pkgmgrinfo_basic.h"
38 #include "pkgmgrinfo_private.h"
39 #include "pkgmgrinfo_debug.h"
40 #include "pkgmgr-info.h"
41 #include "manager/pkginfo_manager.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_metadata_node(gpointer data)
75 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
83 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
87 free((void *)data->locale);
91 pkgmgrinfo_basic_free_package(data->pkg_info);
97 static void __free_packages(gpointer data)
99 pkgmgrinfo_basic_free_package((package_x *)data);
102 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
109 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
116 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
117 pkgmgrinfo_filter_x *filter, int flag,
118 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
122 pkgmgr_pkginfo_x info;
127 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
130 return PMINFO_R_ERROR;
132 if (__check_disable_filter_exist(filter) == false) {
133 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
134 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
135 if (ret != PMINFO_R_OK) {
136 _LOGE("Failed to add filter");
137 g_hash_table_destroy(list);
138 return PMINFO_R_ERROR;
142 ret = _pkginfo_get_packages(uid, filter, flag, list);
143 if (ret == PMINFO_R_ERROR) {
144 g_hash_table_destroy(list);
148 g_hash_table_iter_init(&iter, list);
149 while (g_hash_table_iter_next(&iter, NULL, &value)) {
150 pkg = (package_x *)value;
153 info.locale = pkg->locale;
154 if (pkg_list_cb(&info, user_data) < 0)
158 g_hash_table_destroy(list);
163 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
164 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
168 pkgmgr_pkginfo_x *info;
170 if (pkgid == NULL || filter == NULL || handle == NULL) {
171 LOGE("invalid parameter");
172 return PMINFO_R_EINVAL;
175 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
178 return PMINFO_R_ERROR;
180 ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
181 if (ret != PMINFO_R_OK) {
182 g_hash_table_destroy(list);
186 if (!g_hash_table_size(list) || !g_hash_table_lookup(list, pkgid)) {
187 _LOGD("pkginfo for [%s] is not existed for user [%d]",
189 g_hash_table_destroy(list);
190 return PMINFO_R_ENOENT;
193 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
195 _LOGE("out of memory");
196 g_hash_table_destroy(list);
197 return PMINFO_R_ERROR;
201 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
202 info->locale = strdup(info->pkg_info->locale);
203 if (info->locale == NULL) {
204 _LOGE("Out of memory");
205 g_hash_table_destroy(list);
207 return PMINFO_R_ERROR;
210 /* just free list only */
211 g_hash_table_steal(list, (gconstpointer)pkgid);
212 g_hash_table_destroy(list);
219 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
220 pkgmgrinfo_pkginfo_h *handle)
223 pkgmgrinfo_pkginfo_filter_h filter;
225 if (pkgid == NULL || handle == NULL) {
226 LOGE("invalid parameter");
227 return PMINFO_R_EINVAL;
230 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
231 if (ret != PMINFO_R_OK)
234 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
235 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
236 if (ret != PMINFO_R_OK) {
237 pkgmgrinfo_pkginfo_filter_destroy(filter);
238 return PMINFO_R_ERROR;
241 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
242 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
243 if (ret != PMINFO_R_OK) {
244 pkgmgrinfo_pkginfo_filter_destroy(filter);
245 return PMINFO_R_ERROR;
247 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
248 pkgmgrinfo_pkginfo_filter_destroy(filter);
253 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
254 pkgmgrinfo_pkginfo_h *handle)
256 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
259 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
260 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
263 pkgmgrinfo_pkginfo_filter_h filter;
265 if (pkgid == NULL || handle == NULL) {
266 LOGE("invalid parameter");
267 return PMINFO_R_EINVAL;
270 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
271 if (ret != PMINFO_R_OK) {
275 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
276 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
277 if (ret != PMINFO_R_OK) {
278 pkgmgrinfo_pkginfo_filter_destroy(filter);
279 return PMINFO_R_ERROR;
282 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
283 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
284 if (ret != PMINFO_R_OK) {
285 pkgmgrinfo_pkginfo_filter_destroy(filter);
286 return PMINFO_R_ERROR;
289 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
290 if (ret == PMINFO_R_ENOENT)
291 LOGE("disabled pkginfo for [%s] is not existed for user [%d]",
293 pkgmgrinfo_pkginfo_filter_destroy(filter);
297 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
298 pkgmgrinfo_pkginfo_h *handle)
301 pkgmgrinfo_pkginfo_filter_h filter;
303 if (pkgid == NULL || handle == NULL) {
304 LOGE("invalid parameter");
305 return PMINFO_R_EINVAL;
308 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
309 if (ret != PMINFO_R_OK)
312 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
313 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
314 if (ret != PMINFO_R_OK) {
315 pkgmgrinfo_pkginfo_filter_destroy(filter);
316 return PMINFO_R_ERROR;
319 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
320 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
321 if (ret != PMINFO_R_OK) {
322 pkgmgrinfo_pkginfo_filter_destroy(filter);
323 return PMINFO_R_ERROR;
326 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
327 pkgmgrinfo_pkginfo_filter_destroy(filter);
332 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
333 pkgmgrinfo_pkginfo_h *handle)
335 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
339 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
340 pkgmgrinfo_pkginfo_h *handle)
342 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
345 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
346 int flag, void *user_data, uid_t uid)
349 pkgmgrinfo_pkginfo_filter_h filter;
351 if (pkg_list_cb == NULL) {
352 LOGE("invalid parameter");
353 return PMINFO_R_EINVAL;
356 /* create an empty filter */
357 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
358 if (ret != PMINFO_R_OK)
361 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
362 pkg_list_cb, user_data);
364 pkgmgrinfo_pkginfo_filter_destroy(filter);
369 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
370 int flag, void *user_data)
372 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
373 user_data, _getuid());
376 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
377 void *user_data, uid_t uid)
380 pkgmgrinfo_pkginfo_filter_h filter;
382 if (pkg_list_cb == NULL) {
383 LOGE("invalid parameter");
384 return PMINFO_R_EINVAL;
387 /* create an empty filter */
388 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
389 if (ret != PMINFO_R_OK)
392 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
393 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
395 pkgmgrinfo_pkginfo_filter_destroy(filter);
400 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
403 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
407 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
408 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
411 pkgmgrinfo_pkginfo_filter_h filter;
413 if (pkg_list_cb == NULL) {
414 LOGE("invalid parameter");
415 return PMINFO_R_EINVAL;
418 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
419 if (ret != PMINFO_R_OK)
422 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
423 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
424 if (ret != PMINFO_R_OK) {
425 pkgmgrinfo_pkginfo_filter_destroy(filter);
426 return PMINFO_R_ERROR;
429 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
430 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
432 pkgmgrinfo_pkginfo_filter_destroy(filter);
437 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
440 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
444 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
446 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
448 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
449 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
451 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
452 return PMINFO_R_ERROR;
454 *pkg_name = (char *)info->pkg_info->package;
459 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
461 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
463 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
464 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
466 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
467 return PMINFO_R_ERROR;
469 *pkgid = (char *)info->pkg_info->package;
474 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
476 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
478 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
479 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
481 if (info->pkg_info == NULL)
482 return PMINFO_R_ERROR;
484 if (info->pkg_info->type == NULL)
487 *type = (char *)info->pkg_info->type;
492 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
494 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
496 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
497 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
499 if (info->pkg_info == NULL)
500 return PMINFO_R_ERROR;
502 if (info->pkg_info->version == NULL)
505 *version = (char *)info->pkg_info->version;
510 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
512 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
514 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
515 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
517 if (info->pkg_info == NULL)
518 return PMINFO_R_ERROR;
520 if (info->pkg_info->api_version == NULL)
523 *api_version = (char *)info->pkg_info->api_version;
528 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
530 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
533 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
535 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
536 return PMINFO_R_ERROR;
538 *tep_name = (char *)info->pkg_info->tep_name;
543 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
545 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
547 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
548 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
550 if (info->pkg_info == NULL)
551 return PMINFO_R_ERROR;
553 if (info->pkg_info->zip_mount_file == NULL)
554 *zip_mount_file = "";
556 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
561 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
563 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
566 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
568 if (info->pkg_info == NULL)
569 return PMINFO_R_ERROR;
571 if (info->pkg_info->external_path == NULL)
572 return PMINFO_R_ENOENT;
574 *ext_image_path = (char *)info->pkg_info->external_path;
579 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
582 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
585 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
587 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
588 return PMINFO_R_ERROR;
590 val = (char *)info->pkg_info->installlocation;
591 if (strcmp(val, "internal-only") == 0)
592 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
593 else if (strcmp(val, "prefer-external") == 0)
594 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
596 *location = PMINFO_INSTALL_LOCATION_AUTO;
601 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
603 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
607 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
609 if (info->pkg_info == NULL)
610 return PMINFO_R_ERROR;
612 if (info->pkg_info->package_size == NULL) {
615 _LOGE("out of memory");
616 return PMINFO_R_ERROR;
618 info->pkg_info->package_size = temp;
622 *size = atoi((char *)info->pkg_info->package_size);
627 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
630 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
633 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
635 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
636 return PMINFO_R_ERROR;
638 ptr = (icon_x *)info->pkg_info->icon->data;
640 return PMINFO_R_ERROR;
642 /* TODO : should we return empty string if there was no icon? */
643 if (ptr->text == NULL)
651 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
654 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
656 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
657 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
659 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
660 return PMINFO_R_ERROR;
662 ptr = (label_x *)info->pkg_info->label->data;
664 return PMINFO_R_ERROR;
666 /* TODO : should we return empty string if there was no label? */
667 if (ptr->text == NULL)
675 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
678 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
681 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
683 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
684 return PMINFO_R_ERROR;
686 ptr = (description_x *)info->pkg_info->description->data;
688 return PMINFO_R_ERROR;
690 if (ptr->text == NULL)
693 *description = (char *)ptr->text;
698 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
700 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
703 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
704 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
706 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
707 return PMINFO_R_ERROR;
709 author = (author_x *)info->pkg_info->author->data;
711 return PMINFO_R_ERROR;
713 if (author->text == NULL)
716 *author_name = (char *)author->text;
721 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
723 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
726 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
727 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
729 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
730 return PMINFO_R_ERROR;
732 author = (author_x *)info->pkg_info->author->data;
734 return PMINFO_R_ERROR;
736 if (author->email == NULL)
739 *author_email = (char *)author->email;
744 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
746 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
749 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
750 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
752 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
753 return PMINFO_R_ERROR;
755 author = (author_x *)info->pkg_info->author->data;
757 return PMINFO_R_ERROR;
759 if (author->href == NULL)
762 *author_href = (char *)author->href;
767 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
769 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
771 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
772 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
774 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
775 return PMINFO_R_ERROR;
777 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
778 *storage = PMINFO_INTERNAL_STORAGE;
779 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
780 *storage = PMINFO_EXTERNAL_STORAGE;
781 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
782 *storage = PMINFO_EXTENDED_STORAGE;
784 return PMINFO_R_ERROR;
789 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
791 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
793 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
794 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
796 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
797 return PMINFO_R_ERROR;
799 *installed_time = atoi(info->pkg_info->installed_time);
804 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
806 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
809 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
811 if (info->pkg_info == NULL)
812 return PMINFO_R_ERROR;
814 if (info->pkg_info->storeclient_id == NULL)
817 *storeclientid = (char *)info->pkg_info->storeclient_id;
822 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
824 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
827 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
829 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
830 return PMINFO_R_ERROR;
832 *mainappid = (char *)info->pkg_info->mainapp_id;
837 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
839 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
841 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
842 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
844 if (info->pkg_info == NULL)
845 return PMINFO_R_ERROR;
847 if (info->pkg_info->package_url == NULL)
850 *url = (char *)info->pkg_info->package_url;
855 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
857 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
859 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
860 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
862 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
863 return PMINFO_R_ERROR;
865 *path = (char *)info->pkg_info->root_path;
870 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
872 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
874 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
875 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
877 if (info->pkg_info == NULL)
878 return PMINFO_R_ERROR;
880 if (info->pkg_info->csc_path == NULL)
883 *path = (char *)info->pkg_info->csc_path;
888 API int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle,
891 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
894 retvm_if(res_type == NULL, PMINFO_R_EINVAL,
895 "Argument supplied to hold return value is NULL\n");
897 if (info->pkg_info == NULL)
898 return PMINFO_R_ERROR;
900 if (info->pkg_info->res_type == NULL)
901 return PMINFO_R_ENOENT;
903 *res_type = (char *)info->pkg_info->res_type;
908 API int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle,
911 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
913 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
914 retvm_if(res_version == NULL, PMINFO_R_EINVAL,
915 "Argument supplied to hold return value is NULL\n");
917 if (info->pkg_info == NULL)
918 return PMINFO_R_ERROR;
920 if (info->pkg_info->res_version == NULL)
921 return PMINFO_R_ENOENT;
923 *res_version = (char *)info->pkg_info->res_version;
928 API int pkgmgrinfo_pkginfo_get_light_user_switch_mode(pkgmgrinfo_pkginfo_h handle, char **mode)
930 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
933 retvm_if(mode == NULL, PMINFO_R_EINVAL,
934 "Argument supplied to hold return value is NULL\n");
936 if (info->pkg_info == NULL)
937 return PMINFO_R_ERROR;
939 if (info->pkg_info->light_user_switch_mode == NULL)
940 return PMINFO_R_ERROR;
942 *mode = (char *)info->pkg_info->light_user_switch_mode;
947 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
949 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
950 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
952 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
953 if (info->pkg_info->support_mode)
954 *support_mode = atoi(info->pkg_info->support_mode);
961 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
963 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
964 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
966 #if 0 /* smack issue occured, check later */
968 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
970 _LOGD("invalid func parameters\n");
971 return PMINFO_R_ERROR;
973 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
976 char app_mmc_path[FILENAME_MAX] = { 0, };
977 char app_dir_path[FILENAME_MAX] = { 0, };
978 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
979 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
980 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
981 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
983 /*check whether application is in external memory or not */
984 fp = fopen(app_mmc_path, "r");
986 _LOGD(" app path in external memory not accesible\n");
991 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
995 /*check whether application is in internal or not */
997 _LOGD(" app path in internal memory not accesible\n");
999 return PMINFO_R_ERROR;
1002 /*check whether the application is installed in SD card
1003 but SD card is not present*/
1004 fp = fopen(app_mmc_internal_path, "r");
1007 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1011 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1016 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1023 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1025 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1027 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1028 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1030 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1031 return PMINFO_R_ERROR;
1033 *removable = _get_bool_value(info->pkg_info->removable);
1038 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1044 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1046 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1047 return PMINFO_R_ERROR;
1049 val = (char *)info->pkg_info->installlocation;
1050 if (strcmp(val, "internal-only") == 0)
1058 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1060 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1062 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1063 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1065 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1066 return PMINFO_R_ERROR;
1068 *preload = _get_bool_value(info->pkg_info->preload);
1073 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1075 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1077 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1078 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1080 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1081 return PMINFO_R_ERROR;
1083 *system = _get_bool_value(info->pkg_info->system);
1088 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1090 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1093 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1095 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1096 return PMINFO_R_ERROR;
1098 *readonly = _get_bool_value(info->pkg_info->readonly);
1103 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1105 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1108 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1110 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1111 return PMINFO_R_ERROR;
1113 *update = _get_bool_value(info->pkg_info->update);
1118 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1120 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1122 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1123 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1125 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1126 return PMINFO_R_ERROR;
1128 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1133 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
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(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1140 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1141 return PMINFO_R_ERROR;
1143 *global = _get_bool_value(info->pkg_info->for_all_users);
1148 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1150 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1153 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1155 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1159 __cleanup_pkginfo(info);
1164 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1166 pkgmgrinfo_filter_x *filter;
1168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1170 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1171 if (filter == NULL) {
1172 _LOGE("Out of Memory!!!");
1173 return PMINFO_R_ERROR;
1181 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1183 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1188 g_slist_free_full(filter->list,
1189 (GDestroyNotify)_pkgmgrinfo_node_destroy);
1191 if (filter->list_metadata)
1192 g_slist_free_full(filter->list_metadata,
1193 __destroy_metadata_node);
1200 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1201 const char *property, const int value)
1203 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1207 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1208 pkgmgrinfo_node_x *node;
1210 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1211 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1213 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1214 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1215 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1216 _LOGE("Invalid Integer Property\n");
1217 return PMINFO_R_EINVAL;
1219 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1221 _LOGE("Out of Memory!!!\n");
1222 return PMINFO_R_ERROR;
1224 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1225 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1227 _LOGE("Out of Memory\n");
1229 return PMINFO_R_ERROR;
1233 /*If API is called multiple times for same property, we should override the previous values.
1234 Last value set will be used for filtering.*/
1235 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1237 _pkgmgrinfo_node_destroy(link->data);
1238 filter->list = g_slist_delete_link(filter->list, link);
1240 filter->list = g_slist_append(filter->list, (gpointer)node);
1245 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1246 const char *property, const bool value)
1251 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1252 pkgmgrinfo_node_x *node;
1254 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1255 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1257 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1258 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1259 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1260 _LOGE("Invalid Boolean Property\n");
1261 return PMINFO_R_EINVAL;
1263 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1265 _LOGE("Out of Memory!!!\n");
1266 return PMINFO_R_ERROR;
1269 val = strndup("true", 4);
1271 val = strndup("false", 5);
1273 _LOGE("Out of Memory\n");
1275 return PMINFO_R_ERROR;
1279 /*If API is called multiple times for same property, we should override the previous values.
1280 Last value set will be used for filtering.*/
1281 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1283 _pkgmgrinfo_node_destroy(link->data);
1284 filter->list = g_slist_delete_link(filter->list, link);
1286 filter->list = g_slist_append(filter->list, (gpointer)node);
1291 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1292 const char *property, const char *value)
1297 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1298 pkgmgrinfo_node_x *node;
1300 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1301 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1302 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1304 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1305 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1306 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1307 _LOGE("Invalid String Property\n");
1308 return PMINFO_R_EINVAL;
1310 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1312 _LOGE("Out of Memory!!!\n");
1313 return PMINFO_R_ERROR;
1315 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1316 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1317 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1318 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1319 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1320 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1321 else if (strcmp(value, "installed_internal") == 0)
1322 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1323 else if (strcmp(value, "installed_external") == 0)
1324 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1326 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1328 _LOGE("Out of Memory\n");
1330 return PMINFO_R_ERROR;
1334 /*If API is called multiple times for same property, we should override the previous values.
1335 Last value set will be used for filtering.*/
1336 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1338 _pkgmgrinfo_node_destroy(link->data);
1339 filter->list = g_slist_delete_link(filter->list, link);
1341 filter->list = g_slist_append(filter->list, (gpointer)node);
1346 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1350 GHashTable *list = NULL;
1352 if (handle == NULL || count == NULL) {
1353 _LOGE("invalid parameter");
1354 return PMINFO_R_EINVAL;
1357 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1360 return PMINFO_R_ERROR;
1362 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1363 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1364 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1365 if (ret != PMINFO_R_OK) {
1366 g_hash_table_destroy(list);
1367 return PMINFO_R_ERROR;
1371 ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
1372 query_count = g_hash_table_size(list);
1373 g_hash_table_destroy(list);
1374 if (ret == PMINFO_R_ERROR)
1376 *count = query_count;
1380 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1382 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1385 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1386 pkgmgrinfo_pkginfo_filter_h handle,
1387 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1389 if (handle == NULL || pkg_cb == NULL) {
1390 LOGE("invalid parameter");
1391 return PMINFO_R_EINVAL;
1394 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1395 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1398 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1399 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1401 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1404 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1405 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1407 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1408 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1410 privilege_x *privilege;
1411 appdefined_privilege_x *appdefined_privilege;
1413 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1415 if (info->pkg_info == NULL)
1416 return PMINFO_R_ERROR;
1418 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1419 privilege = (privilege_x *)tmp->data;
1420 if (privilege == NULL)
1422 ret = privilege_func(privilege->value, user_data);
1427 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1429 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
1430 if (appdefined_privilege == NULL)
1432 ret = privilege_func(appdefined_privilege->value, user_data);
1439 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
1440 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
1442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1443 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
1444 "Callback function is NULL");
1448 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1450 if (info->pkg_info == NULL)
1451 return PMINFO_R_ERROR;
1453 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
1454 plugin = (plugin_x *)tmp->data;
1457 ret = plugin_func(plugin->pkgid, plugin->appid,
1458 plugin->plugin_type, plugin->plugin_name, user_data);
1466 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1467 pkgmgrinfo_pkginfo_h handle,
1468 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1472 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1473 "Callback function is NULL");
1475 appdefined_privilege_x *privilege;
1477 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1479 if (info->pkg_info == NULL)
1480 return PMINFO_R_ERROR;
1482 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1484 privilege = (appdefined_privilege_x *)tmp->data;
1485 if (privilege == NULL)
1487 ret = privilege_func(privilege->value, privilege->license,
1495 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
1496 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1500 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1502 dependency_x *dependency;
1504 if (handle == NULL || dependency_cb == NULL) {
1505 LOGE("invalid parameter");
1506 return PMINFO_R_EINVAL;
1509 if (info->pkg_info == NULL)
1510 return PMINFO_R_ERROR;
1512 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
1513 dependency = (dependency_x *)tmp->data;
1514 if (dependency == NULL)
1516 ret = dependency_cb(info->pkg_info->package,
1517 dependency->depends_on, dependency->type,
1518 dependency->required_version, user_data);
1526 static void __free_depends_on(gpointer data)
1528 dependency_x *dep = (dependency_x *)data;
1529 pkgmgrinfo_basic_free_dependency(dep);
1532 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
1533 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1537 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1538 GList *pkg_list = NULL;
1542 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
1543 LOGE("invalid parameter");
1544 return PMINFO_R_EINVAL;
1547 ret = _pkginfo_get_depends_on(info->uid, info->pkg_info->package, &pkg_list);
1548 if (ret != PMINFO_R_OK)
1549 return PMINFO_R_ERROR;
1551 for (l = pkg_list; l != NULL; l = g_list_next(l)) {
1552 dep = (dependency_x *)l->data;
1553 ret = dependency_cb(dep->pkgid, dep->depends_on,
1554 dep->type, dep->required_version, user_data);
1558 g_list_free_full(pkg_list, __free_depends_on);
1563 API int pkgmgrinfo_pkginfo_foreach_res_allowed_package(
1564 pkgmgrinfo_pkginfo_h handle,
1565 pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
1569 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1571 res_allowed_package_x *res_allowed_package;
1573 if (handle == NULL || res_allowed_package_cb == NULL) {
1574 LOGE("invalid parameter");
1575 return PMINFO_R_EINVAL;
1578 if (info->pkg_info == NULL)
1579 return PMINFO_R_ERROR;
1581 for (res_pkgs = info->pkg_info->res_allowed_packages; res_pkgs;
1582 res_pkgs = res_pkgs->next) {
1583 res_allowed_package = (res_allowed_package_x *)res_pkgs->data;
1584 if (res_allowed_package == NULL)
1587 ret = res_allowed_package_cb(
1588 res_allowed_package->allowed_package,
1589 res_allowed_package->required_privileges,
1598 API int pkgmgrinfo_pkginfo_foreach_required_privilege(
1599 required_privilege_h handle,
1600 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1606 if (privilege_func == NULL) {
1607 LOGE("invalid parameter");
1608 return PMINFO_R_EINVAL;
1611 for (privs = (GList *)handle; privs; privs = privs->next) {
1612 ret = privilege_func((char *)privs->data, user_data);
1620 int __compare_package_version(const char *version, int *major,
1621 int *minor, int *macro, int *nano)
1623 char *version_temp = NULL;
1624 char *major_str = NULL;
1625 char *minor_str = NULL;
1626 char *macro_str = NULL;
1627 char *nano_str = NULL;
1628 char *save_str = NULL;
1630 if (version == NULL || major == NULL || minor == NULL ||
1631 macro == NULL || nano == NULL) {
1632 return PMINFO_R_EINVAL;
1635 version_temp = strdup(version);
1636 if (version_temp == NULL) {
1637 LOGE("Out of memory");
1638 return PMINFO_R_ERROR;
1641 major_str = strtok_r(version_temp, ".", &save_str);
1642 if (major_str == NULL) {
1643 _LOGE("major version is NULL");
1645 return PMINFO_R_ERROR;
1648 minor_str = strtok_r(NULL, ".", &save_str);
1649 if (minor_str == NULL) {
1650 _LOGE("minor version is NULL");
1652 return PMINFO_R_ERROR;
1655 *major = atoi(major_str);
1656 *minor = atoi(minor_str);
1659 macro_str = strtok_r(NULL, ".", &save_str);
1660 if (macro_str == NULL) {
1661 _LOGD("macro version is NULL");
1663 *macro = atoi(macro_str);
1664 nano_str = strtok_r(NULL, ".", &save_str);
1666 *nano = atoi(nano_str);
1667 _LOGD("nano version exists");
1670 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1671 " macro = [%d], nano = [%d]", version, *major,
1672 *minor, *macro, *nano);
1679 API int pkgmgrinfo_compare_package_version(const char *current_version,
1680 const char *target_version,
1681 pkgmgrinfo_version_compare_type *res)
1684 int current_version_major = 0;
1685 int current_version_minor = 0;
1686 int current_version_macro = 0;
1687 int current_version_nano = 0;
1688 int target_version_major = 0;
1689 int target_version_minor = 0;
1690 int target_version_macro = 0;
1691 int target_version_nano = 0;
1693 if (current_version == NULL || target_version == NULL ||
1695 _LOGE("Invalid parameter");
1696 return PMINFO_R_EINVAL;
1699 ret = __compare_package_version(target_version,
1700 &target_version_major, &target_version_minor,
1701 &target_version_macro, &target_version_nano);
1703 _LOGE("Failed to compare target version(%d)", ret);
1704 return PMINFO_R_ERROR;
1707 ret = __compare_package_version(current_version,
1708 ¤t_version_major, ¤t_version_minor,
1709 ¤t_version_macro, ¤t_version_nano);
1711 _LOGE("Failed to compare current version(%d)", ret);
1712 return PMINFO_R_ERROR;
1715 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1716 target_version_minor, target_version_macro,
1717 target_version_nano, current_version_major,
1718 current_version_minor, current_version_macro,
1719 target_version_nano);
1721 if (target_version_major > current_version_major)
1722 *res = PMINFO_VERSION_NEW;
1723 else if (target_version_major < current_version_major)
1724 *res = PMINFO_VERSION_OLD;
1725 else if (target_version_minor > current_version_minor)
1726 *res = PMINFO_VERSION_NEW;
1727 else if (target_version_minor < current_version_minor)
1728 *res = PMINFO_VERSION_OLD;
1729 else if (target_version_macro > current_version_macro)
1730 *res = PMINFO_VERSION_NEW;
1731 else if (target_version_macro < current_version_macro)
1732 *res = PMINFO_VERSION_OLD;
1733 else if (target_version_nano > current_version_nano)
1734 *res = PMINFO_VERSION_NEW;
1735 else if (target_version_nano < current_version_nano)
1736 *res = PMINFO_VERSION_OLD;
1738 *res = PMINFO_VERSION_SAME;