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_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
930 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
931 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
933 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
934 if (info->pkg_info->support_mode)
935 *support_mode = atoi(info->pkg_info->support_mode);
942 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
945 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
947 #if 0 /* smack issue occured, check later */
949 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
951 _LOGD("invalid func parameters\n");
952 return PMINFO_R_ERROR;
954 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
957 char app_mmc_path[FILENAME_MAX] = { 0, };
958 char app_dir_path[FILENAME_MAX] = { 0, };
959 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
960 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
961 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
962 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
964 /*check whether application is in external memory or not */
965 fp = fopen(app_mmc_path, "r");
967 _LOGD(" app path in external memory not accesible\n");
972 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
976 /*check whether application is in internal or not */
978 _LOGD(" app path in internal memory not accesible\n");
980 return PMINFO_R_ERROR;
983 /*check whether the application is installed in SD card
984 but SD card is not present*/
985 fp = fopen(app_mmc_internal_path, "r");
988 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
992 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
997 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1004 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1006 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1009 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1011 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1012 return PMINFO_R_ERROR;
1014 *removable = _get_bool_value(info->pkg_info->removable);
1019 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1022 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1025 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1027 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1028 return PMINFO_R_ERROR;
1030 val = (char *)info->pkg_info->installlocation;
1031 if (strcmp(val, "internal-only") == 0)
1039 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
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(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1046 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1047 return PMINFO_R_ERROR;
1049 *preload = _get_bool_value(info->pkg_info->preload);
1054 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1056 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1059 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1061 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1062 return PMINFO_R_ERROR;
1064 *system = _get_bool_value(info->pkg_info->system);
1069 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1071 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1074 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1076 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1077 return PMINFO_R_ERROR;
1079 *readonly = _get_bool_value(info->pkg_info->readonly);
1084 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1086 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1088 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1089 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1091 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1092 return PMINFO_R_ERROR;
1094 *update = _get_bool_value(info->pkg_info->update);
1099 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1101 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1104 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1106 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1107 return PMINFO_R_ERROR;
1109 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1114 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1116 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1118 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1119 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1121 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1122 return PMINFO_R_ERROR;
1124 *global = _get_bool_value(info->pkg_info->for_all_users);
1129 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1131 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1134 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1136 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1140 __cleanup_pkginfo(info);
1145 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1147 pkgmgrinfo_filter_x *filter;
1149 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1151 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1152 if (filter == NULL) {
1153 _LOGE("Out of Memory!!!");
1154 return PMINFO_R_ERROR;
1162 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1164 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1169 g_slist_free_full(filter->list,
1170 (GDestroyNotify)_pkgmgrinfo_node_destroy);
1172 if (filter->list_metadata)
1173 g_slist_free_full(filter->list_metadata,
1174 __destroy_metadata_node);
1181 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1182 const char *property, const int value)
1184 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1188 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1189 pkgmgrinfo_node_x *node;
1191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1192 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1194 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1195 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1196 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1197 _LOGE("Invalid Integer Property\n");
1198 return PMINFO_R_EINVAL;
1200 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1202 _LOGE("Out of Memory!!!\n");
1203 return PMINFO_R_ERROR;
1205 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1206 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1208 _LOGE("Out of Memory\n");
1210 return PMINFO_R_ERROR;
1214 /*If API is called multiple times for same property, we should override the previous values.
1215 Last value set will be used for filtering.*/
1216 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1218 _pkgmgrinfo_node_destroy(link->data);
1219 filter->list = g_slist_delete_link(filter->list, link);
1221 filter->list = g_slist_append(filter->list, (gpointer)node);
1226 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1227 const char *property, const bool value)
1232 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1233 pkgmgrinfo_node_x *node;
1235 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1236 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1238 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1239 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1240 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1241 _LOGE("Invalid Boolean Property\n");
1242 return PMINFO_R_EINVAL;
1244 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1246 _LOGE("Out of Memory!!!\n");
1247 return PMINFO_R_ERROR;
1250 val = strndup("true", 4);
1252 val = strndup("false", 5);
1254 _LOGE("Out of Memory\n");
1256 return PMINFO_R_ERROR;
1260 /*If API is called multiple times for same property, we should override the previous values.
1261 Last value set will be used for filtering.*/
1262 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1264 _pkgmgrinfo_node_destroy(link->data);
1265 filter->list = g_slist_delete_link(filter->list, link);
1267 filter->list = g_slist_append(filter->list, (gpointer)node);
1272 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1273 const char *property, const char *value)
1278 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1279 pkgmgrinfo_node_x *node;
1281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1282 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1283 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1285 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1286 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1287 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1288 _LOGE("Invalid String Property\n");
1289 return PMINFO_R_EINVAL;
1291 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1293 _LOGE("Out of Memory!!!\n");
1294 return PMINFO_R_ERROR;
1296 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1297 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1298 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1299 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1300 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1301 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1302 else if (strcmp(value, "installed_internal") == 0)
1303 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1304 else if (strcmp(value, "installed_external") == 0)
1305 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1307 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1309 _LOGE("Out of Memory\n");
1311 return PMINFO_R_ERROR;
1315 /*If API is called multiple times for same property, we should override the previous values.
1316 Last value set will be used for filtering.*/
1317 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1319 _pkgmgrinfo_node_destroy(link->data);
1320 filter->list = g_slist_delete_link(filter->list, link);
1322 filter->list = g_slist_append(filter->list, (gpointer)node);
1327 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1331 GHashTable *list = NULL;
1333 if (handle == NULL || count == NULL) {
1334 _LOGE("invalid parameter");
1335 return PMINFO_R_EINVAL;
1338 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1341 return PMINFO_R_ERROR;
1343 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1344 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1345 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1346 if (ret != PMINFO_R_OK) {
1347 g_hash_table_destroy(list);
1348 return PMINFO_R_ERROR;
1352 ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
1353 query_count = g_hash_table_size(list);
1354 g_hash_table_destroy(list);
1355 if (ret == PMINFO_R_ERROR)
1357 *count = query_count;
1361 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1363 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1366 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1367 pkgmgrinfo_pkginfo_filter_h handle,
1368 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1370 if (handle == NULL || pkg_cb == NULL) {
1371 LOGE("invalid parameter");
1372 return PMINFO_R_EINVAL;
1375 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1376 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1379 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1380 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1382 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1385 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1386 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1388 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1389 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1391 privilege_x *privilege;
1392 appdefined_privilege_x *appdefined_privilege;
1394 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1396 if (info->pkg_info == NULL)
1397 return PMINFO_R_ERROR;
1399 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1400 privilege = (privilege_x *)tmp->data;
1401 if (privilege == NULL)
1403 ret = privilege_func(privilege->value, user_data);
1408 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1410 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
1411 if (appdefined_privilege == NULL)
1413 ret = privilege_func(appdefined_privilege->value, user_data);
1420 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
1421 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
1423 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1424 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
1425 "Callback function is NULL");
1429 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1431 if (info->pkg_info == NULL)
1432 return PMINFO_R_ERROR;
1434 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
1435 plugin = (plugin_x *)tmp->data;
1438 ret = plugin_func(plugin->pkgid, plugin->appid,
1439 plugin->plugin_type, plugin->plugin_name, user_data);
1447 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1448 pkgmgrinfo_pkginfo_h handle,
1449 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1452 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1453 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1454 "Callback function is NULL");
1456 appdefined_privilege_x *privilege;
1458 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1460 if (info->pkg_info == NULL)
1461 return PMINFO_R_ERROR;
1463 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1465 privilege = (appdefined_privilege_x *)tmp->data;
1466 if (privilege == NULL)
1468 ret = privilege_func(privilege->value, privilege->license,
1476 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
1477 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1481 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1483 dependency_x *dependency;
1485 if (handle == NULL || dependency_cb == NULL) {
1486 LOGE("invalid parameter");
1487 return PMINFO_R_EINVAL;
1490 if (info->pkg_info == NULL)
1491 return PMINFO_R_ERROR;
1493 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
1494 dependency = (dependency_x *)tmp->data;
1495 if (dependency == NULL)
1497 ret = dependency_cb(info->pkg_info->package,
1498 dependency->depends_on, dependency->type,
1499 dependency->required_version, user_data);
1507 static void __free_depends_on(gpointer data)
1509 dependency_x *dep = (dependency_x *)data;
1510 pkgmgrinfo_basic_free_dependency(dep);
1513 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
1514 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1518 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1519 GList *pkg_list = NULL;
1523 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
1524 LOGE("invalid parameter");
1525 return PMINFO_R_EINVAL;
1528 ret = _pkginfo_get_depends_on(info->uid, info->pkg_info->package, &pkg_list);
1529 if (ret != PMINFO_R_OK)
1530 return PMINFO_R_ERROR;
1532 for (l = pkg_list; l != NULL; l = g_list_next(l)) {
1533 dep = (dependency_x *)l->data;
1534 ret = dependency_cb(dep->pkgid, dep->depends_on,
1535 dep->type, dep->required_version, user_data);
1539 g_list_free_full(pkg_list, __free_depends_on);
1544 API int pkgmgrinfo_pkginfo_foreach_res_allowed_package(
1545 pkgmgrinfo_pkginfo_h handle,
1546 pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
1550 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1552 res_allowed_package_x *res_allowed_package;
1554 if (handle == NULL || res_allowed_package_cb == NULL) {
1555 LOGE("invalid parameter");
1556 return PMINFO_R_EINVAL;
1559 if (info->pkg_info == NULL)
1560 return PMINFO_R_ERROR;
1562 for (res_pkgs = info->pkg_info->res_allowed_packages; res_pkgs;
1563 res_pkgs = res_pkgs->next) {
1564 res_allowed_package = (res_allowed_package_x *)res_pkgs->data;
1565 if (res_allowed_package == NULL)
1568 ret = res_allowed_package_cb(
1569 res_allowed_package->allowed_package,
1570 res_allowed_package->required_privileges,
1579 API int pkgmgrinfo_pkginfo_foreach_required_privilege(
1580 required_privilege_h handle,
1581 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1587 if (privilege_func == NULL) {
1588 LOGE("invalid parameter");
1589 return PMINFO_R_EINVAL;
1592 for (privs = (GList *)handle; privs; privs = privs->next) {
1593 ret = privilege_func((char *)privs->data, user_data);
1601 int __compare_package_version(const char *version, int *major,
1602 int *minor, int *macro, int *nano)
1604 char *version_temp = NULL;
1605 char *major_str = NULL;
1606 char *minor_str = NULL;
1607 char *macro_str = NULL;
1608 char *nano_str = NULL;
1609 char *save_str = NULL;
1611 if (version == NULL || major == NULL || minor == NULL ||
1612 macro == NULL || nano == NULL) {
1613 return PMINFO_R_EINVAL;
1616 version_temp = strdup(version);
1617 if (version_temp == NULL) {
1618 LOGE("Out of memory");
1619 return PMINFO_R_ERROR;
1622 major_str = strtok_r(version_temp, ".", &save_str);
1623 if (major_str == NULL) {
1624 _LOGE("major version is NULL");
1626 return PMINFO_R_ERROR;
1629 minor_str = strtok_r(NULL, ".", &save_str);
1630 if (minor_str == NULL) {
1631 _LOGE("minor version is NULL");
1633 return PMINFO_R_ERROR;
1636 *major = atoi(major_str);
1637 *minor = atoi(minor_str);
1640 macro_str = strtok_r(NULL, ".", &save_str);
1641 if (macro_str == NULL) {
1642 _LOGD("macro version is NULL");
1644 *macro = atoi(macro_str);
1645 nano_str = strtok_r(NULL, ".", &save_str);
1647 *nano = atoi(nano_str);
1648 _LOGD("nano version exists");
1651 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1652 " macro = [%d], nano = [%d]", version, *major,
1653 *minor, *macro, *nano);
1660 API int pkgmgrinfo_compare_package_version(const char *current_version,
1661 const char *target_version,
1662 pkgmgrinfo_version_compare_type *res)
1665 int current_version_major = 0;
1666 int current_version_minor = 0;
1667 int current_version_macro = 0;
1668 int current_version_nano = 0;
1669 int target_version_major = 0;
1670 int target_version_minor = 0;
1671 int target_version_macro = 0;
1672 int target_version_nano = 0;
1674 if (current_version == NULL || target_version == NULL ||
1676 _LOGE("Invalid parameter");
1677 return PMINFO_R_EINVAL;
1680 ret = __compare_package_version(target_version,
1681 &target_version_major, &target_version_minor,
1682 &target_version_macro, &target_version_nano);
1684 _LOGE("Failed to compare target version(%d)", ret);
1685 return PMINFO_R_ERROR;
1688 ret = __compare_package_version(current_version,
1689 ¤t_version_major, ¤t_version_minor,
1690 ¤t_version_macro, ¤t_version_nano);
1692 _LOGE("Failed to compare current version(%d)", ret);
1693 return PMINFO_R_ERROR;
1696 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1697 target_version_minor, target_version_macro,
1698 target_version_nano, current_version_major,
1699 current_version_minor, current_version_macro,
1700 target_version_nano);
1702 if (target_version_major > current_version_major)
1703 *res = PMINFO_VERSION_NEW;
1704 else if (target_version_major < current_version_major)
1705 *res = PMINFO_VERSION_OLD;
1706 else if (target_version_minor > current_version_minor)
1707 *res = PMINFO_VERSION_NEW;
1708 else if (target_version_minor < current_version_minor)
1709 *res = PMINFO_VERSION_OLD;
1710 else if (target_version_macro > current_version_macro)
1711 *res = PMINFO_VERSION_NEW;
1712 else if (target_version_macro < current_version_macro)
1713 *res = PMINFO_VERSION_OLD;
1714 else if (target_version_nano > current_version_nano)
1715 *res = PMINFO_VERSION_NEW;
1716 else if (target_version_nano < current_version_nano)
1717 *res = PMINFO_VERSION_OLD;
1719 *res = PMINFO_VERSION_SAME;