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"
42 #include "manager/pkginfo_manager.h"
44 static bool _get_bool_value(const char *str)
46 if (str && !strcmp(str, "true"))
52 static gint __compare_func(gconstpointer data1, gconstpointer data2)
54 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
55 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
56 if (node1->prop == node2->prop)
58 else if (node1->prop > node2->prop)
64 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
66 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
68 if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
74 static void __destroy_each_node(gpointer data, gpointer user_data)
77 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
90 static void __destroy_metadata_node(gpointer data)
92 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
100 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
102 ret_if(data == NULL);
104 free((void *)data->locale);
108 pkgmgrinfo_basic_free_package(data->pkg_info);
114 static void __free_packages(gpointer data)
116 pkgmgrinfo_basic_free_package((package_x *)data);
119 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
126 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
133 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
134 pkgmgrinfo_filter_x *filter, int flag,
135 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
139 pkgmgr_pkginfo_x info;
144 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
147 return PMINFO_R_ERROR;
149 if (__check_disable_filter_exist(filter) == false) {
150 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
151 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
152 if (ret != PMINFO_R_OK) {
153 _LOGE("Failed to add filter");
154 g_hash_table_destroy(list);
155 return PMINFO_R_ERROR;
159 ret = _pkginfo_get_packages(uid, filter, flag, list);
160 if (ret != PMINFO_R_OK) {
161 g_hash_table_destroy(list);
162 return PMINFO_R_ERROR;
165 g_hash_table_iter_init(&iter, list);
166 while (g_hash_table_iter_next(&iter, NULL, &value)) {
167 pkg = (package_x *)value;
170 info.locale = pkg->locale;
171 if (pkg_list_cb(&info, user_data) < 0)
175 g_hash_table_destroy(list);
180 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
181 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
185 pkgmgr_pkginfo_x *info;
187 if (pkgid == NULL || filter == NULL || handle == NULL) {
188 LOGE("invalid parameter");
189 return PMINFO_R_EINVAL;
192 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
195 return PMINFO_R_ERROR;
197 ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
198 if (ret != PMINFO_R_OK) {
199 g_hash_table_destroy(list);
203 if (!g_hash_table_size(list)) {
204 _LOGD("pkginfo for [%s] is not existed for user [%d]",
206 g_hash_table_destroy(list);
207 return PMINFO_R_ENOENT;
210 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
212 _LOGE("out of memory");
213 g_hash_table_destroy(list);
214 return PMINFO_R_ERROR;
218 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
219 info->locale = strdup(info->pkg_info->locale);
220 if (info->locale == NULL) {
221 _LOGE("Out of memory");
222 g_hash_table_destroy(list);
224 return PMINFO_R_ERROR;
227 /* just free list only */
228 g_hash_table_steal(list, (gconstpointer)pkgid);
229 g_hash_table_destroy(list);
236 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
237 pkgmgrinfo_pkginfo_h *handle)
240 pkgmgrinfo_pkginfo_filter_h filter;
242 if (pkgid == NULL || handle == NULL) {
243 LOGE("invalid parameter");
244 return PMINFO_R_EINVAL;
247 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
248 if (ret != PMINFO_R_OK)
251 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
252 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
253 if (ret != PMINFO_R_OK) {
254 pkgmgrinfo_pkginfo_filter_destroy(filter);
255 return PMINFO_R_ERROR;
258 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
259 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
260 if (ret != PMINFO_R_OK) {
261 pkgmgrinfo_pkginfo_filter_destroy(filter);
262 return PMINFO_R_ERROR;
264 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
265 pkgmgrinfo_pkginfo_filter_destroy(filter);
270 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
271 pkgmgrinfo_pkginfo_h *handle)
273 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
276 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
277 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
280 pkgmgrinfo_pkginfo_filter_h filter;
282 if (pkgid == NULL || handle == NULL) {
283 LOGE("invalid parameter");
284 return PMINFO_R_EINVAL;
287 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
288 if (ret != PMINFO_R_OK) {
292 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
293 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
294 if (ret != PMINFO_R_OK) {
295 pkgmgrinfo_pkginfo_filter_destroy(filter);
296 return PMINFO_R_ERROR;
299 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
300 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
301 if (ret != PMINFO_R_OK) {
302 pkgmgrinfo_pkginfo_filter_destroy(filter);
303 return PMINFO_R_ERROR;
306 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
307 if (ret == PMINFO_R_ENOENT)
308 LOGE("disabled pkginfo for [%s] is not existed for user [%d]",
310 pkgmgrinfo_pkginfo_filter_destroy(filter);
314 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
315 pkgmgrinfo_pkginfo_h *handle)
318 pkgmgrinfo_pkginfo_filter_h filter;
320 if (pkgid == NULL || handle == NULL) {
321 LOGE("invalid parameter");
322 return PMINFO_R_EINVAL;
325 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
326 if (ret != PMINFO_R_OK)
329 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
330 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
331 if (ret != PMINFO_R_OK) {
332 pkgmgrinfo_pkginfo_filter_destroy(filter);
333 return PMINFO_R_ERROR;
336 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
337 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
338 if (ret != PMINFO_R_OK) {
339 pkgmgrinfo_pkginfo_filter_destroy(filter);
340 return PMINFO_R_ERROR;
343 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
344 pkgmgrinfo_pkginfo_filter_destroy(filter);
349 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
350 pkgmgrinfo_pkginfo_h *handle)
352 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
356 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
357 pkgmgrinfo_pkginfo_h *handle)
359 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
362 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
363 int flag, void *user_data, uid_t uid)
366 pkgmgrinfo_pkginfo_filter_h filter;
368 if (pkg_list_cb == NULL) {
369 LOGE("invalid parameter");
370 return PMINFO_R_EINVAL;
373 /* create an empty filter */
374 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
375 if (ret != PMINFO_R_OK)
378 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
379 pkg_list_cb, user_data);
381 pkgmgrinfo_pkginfo_filter_destroy(filter);
386 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
387 int flag, void *user_data)
389 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
390 user_data, _getuid());
393 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
394 void *user_data, uid_t uid)
397 pkgmgrinfo_pkginfo_filter_h filter;
399 if (pkg_list_cb == NULL) {
400 LOGE("invalid parameter");
401 return PMINFO_R_EINVAL;
404 /* create an empty filter */
405 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
406 if (ret != PMINFO_R_OK)
409 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
410 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
412 pkgmgrinfo_pkginfo_filter_destroy(filter);
417 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
420 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
424 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
425 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
428 pkgmgrinfo_pkginfo_filter_h filter;
430 if (pkg_list_cb == NULL) {
431 LOGE("invalid parameter");
432 return PMINFO_R_EINVAL;
435 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
436 if (ret != PMINFO_R_OK)
439 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
440 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
441 if (ret != PMINFO_R_OK) {
442 pkgmgrinfo_pkginfo_filter_destroy(filter);
443 return PMINFO_R_ERROR;
446 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
447 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
449 pkgmgrinfo_pkginfo_filter_destroy(filter);
454 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
457 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
461 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
463 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
465 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
466 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
468 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
469 return PMINFO_R_ERROR;
471 *pkg_name = (char *)info->pkg_info->package;
476 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
478 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
480 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
481 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
483 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
484 return PMINFO_R_ERROR;
486 *pkgid = (char *)info->pkg_info->package;
491 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
493 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
496 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
498 if (info->pkg_info == NULL)
499 return PMINFO_R_ERROR;
501 if (info->pkg_info->type == NULL)
504 *type = (char *)info->pkg_info->type;
509 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
511 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
514 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
516 if (info->pkg_info == NULL)
517 return PMINFO_R_ERROR;
519 if (info->pkg_info->version == NULL)
522 *version = (char *)info->pkg_info->version;
527 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
529 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
531 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
532 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
534 if (info->pkg_info == NULL)
535 return PMINFO_R_ERROR;
537 if (info->pkg_info->api_version == NULL)
540 *api_version = (char *)info->pkg_info->api_version;
545 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
547 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
549 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
550 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
552 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
553 return PMINFO_R_ERROR;
555 *tep_name = (char *)info->pkg_info->tep_name;
560 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
562 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
565 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
567 if (info->pkg_info == NULL)
568 return PMINFO_R_ERROR;
570 if (info->pkg_info->zip_mount_file == NULL)
571 *zip_mount_file = "";
573 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
578 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
580 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
583 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
585 if (info->pkg_info == NULL)
586 return PMINFO_R_ERROR;
588 if (info->pkg_info->external_path == NULL)
589 return PMINFO_R_ENOENT;
591 *ext_image_path = (char *)info->pkg_info->external_path;
596 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
599 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
601 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
602 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
604 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
605 return PMINFO_R_ERROR;
607 val = (char *)info->pkg_info->installlocation;
608 if (strcmp(val, "internal-only") == 0)
609 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
610 else if (strcmp(val, "prefer-external") == 0)
611 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
613 *location = PMINFO_INSTALL_LOCATION_AUTO;
618 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
620 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
623 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
624 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
626 if (info->pkg_info == NULL)
627 return PMINFO_R_ERROR;
629 if (info->pkg_info->package_size == NULL) {
632 _LOGE("out of memory");
633 return PMINFO_R_ERROR;
635 info->pkg_info->package_size = temp;
639 *size = atoi((char *)info->pkg_info->package_size);
644 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
647 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
649 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
650 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
652 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
653 return PMINFO_R_ERROR;
655 ptr = (icon_x *)info->pkg_info->icon->data;
657 return PMINFO_R_ERROR;
659 /* TODO : should we return empty string if there was no icon? */
660 if (ptr->text == NULL)
668 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
671 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
674 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
676 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
677 return PMINFO_R_ERROR;
679 ptr = (label_x *)info->pkg_info->label->data;
681 return PMINFO_R_ERROR;
683 /* TODO : should we return empty string if there was no label? */
684 if (ptr->text == NULL)
692 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
695 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
697 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
698 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
700 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
701 return PMINFO_R_ERROR;
703 ptr = (description_x *)info->pkg_info->description->data;
705 return PMINFO_R_ERROR;
707 if (ptr->text == NULL)
710 *description = (char *)ptr->text;
715 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
717 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
720 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
721 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
723 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
724 return PMINFO_R_ERROR;
726 author = (author_x *)info->pkg_info->author->data;
728 return PMINFO_R_ERROR;
730 if (author->text == NULL)
733 *author_name = (char *)author->text;
738 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
740 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
743 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
744 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
746 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
747 return PMINFO_R_ERROR;
749 author = (author_x *)info->pkg_info->author->data;
751 return PMINFO_R_ERROR;
753 if (author->email == NULL)
756 *author_email = (char *)author->email;
761 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
763 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
766 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
767 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
769 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
770 return PMINFO_R_ERROR;
772 author = (author_x *)info->pkg_info->author->data;
774 return PMINFO_R_ERROR;
776 if (author->href == NULL)
779 *author_href = (char *)author->href;
784 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
786 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
788 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
789 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
791 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
792 return PMINFO_R_ERROR;
794 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
795 *storage = PMINFO_INTERNAL_STORAGE;
796 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
797 *storage = PMINFO_EXTERNAL_STORAGE;
798 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
799 *storage = PMINFO_EXTENDED_STORAGE;
801 return PMINFO_R_ERROR;
806 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
808 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
810 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
811 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
813 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
814 return PMINFO_R_ERROR;
816 *installed_time = atoi(info->pkg_info->installed_time);
821 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
823 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
825 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
826 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
828 if (info->pkg_info == NULL)
829 return PMINFO_R_ERROR;
831 if (info->pkg_info->storeclient_id == NULL)
834 *storeclientid = (char *)info->pkg_info->storeclient_id;
839 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
841 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
844 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
846 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
847 return PMINFO_R_ERROR;
849 *mainappid = (char *)info->pkg_info->mainapp_id;
854 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
856 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
859 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
861 if (info->pkg_info == NULL)
862 return PMINFO_R_ERROR;
864 if (info->pkg_info->package_url == NULL)
867 *url = (char *)info->pkg_info->package_url;
872 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
874 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
876 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
877 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
879 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
880 return PMINFO_R_ERROR;
882 *path = (char *)info->pkg_info->root_path;
887 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
889 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
891 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
892 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
894 if (info->pkg_info == NULL)
895 return PMINFO_R_ERROR;
897 if (info->pkg_info->csc_path == NULL)
900 *path = (char *)info->pkg_info->csc_path;
905 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
907 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
908 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
910 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
911 if (info->pkg_info->support_mode)
912 *support_mode = atoi(info->pkg_info->support_mode);
919 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
921 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
922 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
924 #if 0 /* smack issue occured, check later */
926 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
928 _LOGD("invalid func parameters\n");
929 return PMINFO_R_ERROR;
931 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
934 char app_mmc_path[FILENAME_MAX] = { 0, };
935 char app_dir_path[FILENAME_MAX] = { 0, };
936 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
937 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
938 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
939 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
941 /*check whether application is in external memory or not */
942 fp = fopen(app_mmc_path, "r");
944 _LOGD(" app path in external memory not accesible\n");
949 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
953 /*check whether application is in internal or not */
955 _LOGD(" app path in internal memory not accesible\n");
957 return PMINFO_R_ERROR;
960 /*check whether the application is installed in SD card
961 but SD card is not present*/
962 fp = fopen(app_mmc_internal_path, "r");
965 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
969 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
974 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
981 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
983 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
986 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
988 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
989 return PMINFO_R_ERROR;
991 *removable = _get_bool_value(info->pkg_info->removable);
996 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
999 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1001 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1002 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1004 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1005 return PMINFO_R_ERROR;
1007 val = (char *)info->pkg_info->installlocation;
1008 if (strcmp(val, "internal-only") == 0)
1016 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1018 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1020 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1021 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1023 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1024 return PMINFO_R_ERROR;
1026 *preload = _get_bool_value(info->pkg_info->preload);
1031 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1033 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1036 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1038 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1039 return PMINFO_R_ERROR;
1041 *system = _get_bool_value(info->pkg_info->system);
1046 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1048 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1051 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1053 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1054 return PMINFO_R_ERROR;
1056 *readonly = _get_bool_value(info->pkg_info->readonly);
1061 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1063 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1066 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1068 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1069 return PMINFO_R_ERROR;
1071 *update = _get_bool_value(info->pkg_info->update);
1076 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1078 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1080 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1081 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1083 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1084 return PMINFO_R_ERROR;
1086 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1091 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1093 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1096 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1098 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1099 return PMINFO_R_ERROR;
1101 *global = _get_bool_value(info->pkg_info->for_all_users);
1106 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1108 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1111 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1113 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1115 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1117 __cleanup_pkginfo(info);
1122 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1124 pkgmgrinfo_filter_x *filter;
1126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1128 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1129 if (filter == NULL) {
1130 _LOGE("Out of Memory!!!");
1131 return PMINFO_R_ERROR;
1139 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1141 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1146 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1147 g_slist_free(filter->list);
1150 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1157 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1158 const char *property, const int value)
1160 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1164 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1165 pkgmgrinfo_node_x *node;
1167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1168 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1170 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1171 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1172 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1173 _LOGE("Invalid Integer Property\n");
1174 return PMINFO_R_EINVAL;
1176 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1178 _LOGE("Out of Memory!!!\n");
1179 return PMINFO_R_ERROR;
1181 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1182 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1184 _LOGE("Out of Memory\n");
1186 return PMINFO_R_ERROR;
1190 /*If API is called multiple times for same property, we should override the previous values.
1191 Last value set will be used for filtering.*/
1192 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1194 filter->list = g_slist_delete_link(filter->list, link);
1195 filter->list = g_slist_append(filter->list, (gpointer)node);
1200 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1201 const char *property, const bool value)
1206 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1207 pkgmgrinfo_node_x *node;
1209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1210 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1212 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1213 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1214 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1215 _LOGE("Invalid Boolean Property\n");
1216 return PMINFO_R_EINVAL;
1218 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1220 _LOGE("Out of Memory!!!\n");
1221 return PMINFO_R_ERROR;
1224 val = strndup("true", 4);
1226 val = strndup("false", 5);
1228 _LOGE("Out of Memory\n");
1230 return PMINFO_R_ERROR;
1234 /*If API is called multiple times for same property, we should override the previous values.
1235 Last value set will be used for filtering.*/
1236 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1238 filter->list = g_slist_delete_link(filter->list, link);
1239 filter->list = g_slist_append(filter->list, (gpointer)node);
1244 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1245 const char *property, const char *value)
1250 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1251 pkgmgrinfo_node_x *node;
1253 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1254 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1255 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1257 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1258 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1259 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1260 _LOGE("Invalid String 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;
1268 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1269 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1270 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1271 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1272 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1273 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1274 else if (strcmp(value, "installed_internal") == 0)
1275 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1276 else if (strcmp(value, "installed_external") == 0)
1277 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1279 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1281 _LOGE("Out of Memory\n");
1283 return PMINFO_R_ERROR;
1287 /*If API is called multiple times for same property, we should override the previous values.
1288 Last value set will be used for filtering.*/
1289 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1291 filter->list = g_slist_delete_link(filter->list, link);
1292 filter->list = g_slist_append(filter->list, (gpointer)node);
1297 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1301 GHashTable *list = NULL;
1303 if (handle == NULL || count == NULL) {
1304 _LOGE("invalid parameter");
1305 return PMINFO_R_EINVAL;
1308 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1311 return PMINFO_R_ERROR;
1313 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1314 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1315 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1316 if (ret != PMINFO_R_OK) {
1317 g_hash_table_destroy(list);
1318 return PMINFO_R_ERROR;
1322 ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
1323 query_count = g_hash_table_size(list);
1324 g_hash_table_destroy(list);
1325 if (ret == PMINFO_R_ERROR)
1327 *count = query_count;
1331 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1333 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1336 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1337 pkgmgrinfo_pkginfo_filter_h handle,
1338 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1340 if (handle == NULL || pkg_cb == NULL) {
1341 LOGE("invalid parameter");
1342 return PMINFO_R_EINVAL;
1345 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1346 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1349 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1350 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1352 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1355 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1356 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1358 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1359 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1361 privilege_x *privilege;
1362 appdefined_privilege_x *appdefined_privilege;
1364 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1366 if (info->pkg_info == NULL)
1367 return PMINFO_R_ERROR;
1369 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1370 privilege = (privilege_x *)tmp->data;
1371 if (privilege == NULL)
1373 ret = privilege_func(privilege->value, user_data);
1378 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1380 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
1381 if (appdefined_privilege == NULL)
1383 ret = privilege_func(appdefined_privilege->value, user_data);
1390 API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
1391 pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
1393 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1394 retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
1395 "Callback function is NULL");
1399 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1401 if (info->pkg_info == NULL)
1402 return PMINFO_R_ERROR;
1404 for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
1405 plugin = (plugin_x *)tmp->data;
1408 ret = plugin_func(plugin->pkgid, plugin->appid,
1409 plugin->plugin_type, plugin->plugin_name, user_data);
1417 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1418 pkgmgrinfo_pkginfo_h handle,
1419 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1422 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1423 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1424 "Callback function is NULL");
1426 appdefined_privilege_x *privilege;
1428 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1430 if (info->pkg_info == NULL)
1431 return PMINFO_R_ERROR;
1433 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1435 privilege = (appdefined_privilege_x *)tmp->data;
1436 if (privilege == NULL)
1438 ret = privilege_func(privilege->value, privilege->license,
1446 API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
1447 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1451 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1453 dependency_x *dependency;
1455 if (handle == NULL || dependency_cb == NULL) {
1456 LOGE("invalid parameter");
1457 return PMINFO_R_EINVAL;
1460 if (info->pkg_info == NULL)
1461 return PMINFO_R_ERROR;
1463 for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
1464 dependency = (dependency_x *)tmp->data;
1465 if (dependency == NULL)
1467 ret = dependency_cb(info->pkg_info->package,
1468 dependency->depends_on, dependency->type,
1469 dependency->required_version, user_data);
1477 static void __free_depends_on(gpointer data)
1479 dependency_x *dep = (dependency_x *)data;
1480 pkgmgrinfo_basic_free_dependency(dep);
1483 API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
1484 pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
1488 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1489 GList *pkg_list = NULL;
1493 if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
1494 LOGE("invalid parameter");
1495 return PMINFO_R_EINVAL;
1498 ret = _pkginfo_get_depends_on(info->uid, info->pkg_info->package, &pkg_list);
1499 if (ret != PMINFO_R_OK)
1500 return PMINFO_R_ERROR;
1502 for (l = pkg_list; l != NULL; l = g_list_next(l)) {
1503 dep = (dependency_x *)l->data;
1504 ret = dependency_cb(dep->pkgid, dep->depends_on,
1505 dep->type, dep->required_version, user_data);
1509 g_list_free_full(pkg_list, __free_depends_on);
1514 int __compare_package_version(const char *version, int *major,
1515 int *minor, int *macro, int *nano)
1517 char *version_temp = NULL;
1518 char *major_str = NULL;
1519 char *minor_str = NULL;
1520 char *macro_str = NULL;
1521 char *nano_str = NULL;
1522 char *save_str = NULL;
1524 if (version == NULL || major == NULL || minor == NULL ||
1525 macro == NULL || nano == NULL) {
1526 return PMINFO_R_EINVAL;
1529 version_temp = strdup(version);
1530 if (version_temp == NULL) {
1531 LOGE("Out of memory");
1532 return PMINFO_R_ERROR;
1535 major_str = strtok_r(version_temp, ".", &save_str);
1536 if (major_str == NULL) {
1537 _LOGE("major version is NULL");
1539 return PMINFO_R_ERROR;
1542 minor_str = strtok_r(NULL, ".", &save_str);
1543 if (minor_str == NULL) {
1544 _LOGE("minor version is NULL");
1546 return PMINFO_R_ERROR;
1549 *major = atoi(major_str);
1550 *minor = atoi(minor_str);
1553 macro_str = strtok_r(NULL, ".", &save_str);
1554 if (macro_str == NULL) {
1555 _LOGD("macro version is NULL");
1557 *macro = atoi(macro_str);
1558 nano_str = strtok_r(NULL, ".", &save_str);
1560 *nano = atoi(nano_str);
1561 _LOGD("nano version exists");
1564 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1565 " macro = [%d], nano = [%d]", version, *major,
1566 *minor, *macro, *nano);
1573 API int pkgmgrinfo_compare_package_version(const char *current_version,
1574 const char *target_version,
1575 pkgmgrinfo_version_compare_type *res)
1578 int current_version_major = 0;
1579 int current_version_minor = 0;
1580 int current_version_macro = 0;
1581 int current_version_nano = 0;
1582 int target_version_major = 0;
1583 int target_version_minor = 0;
1584 int target_version_macro = 0;
1585 int target_version_nano = 0;
1587 if (current_version == NULL || target_version == NULL ||
1589 _LOGE("Invalid parameter");
1590 return PMINFO_R_EINVAL;
1593 ret = __compare_package_version(target_version,
1594 &target_version_major, &target_version_minor,
1595 &target_version_macro, &target_version_nano);
1597 _LOGE("Failed to compare target version(%d)", ret);
1598 return PMINFO_R_ERROR;
1601 ret = __compare_package_version(current_version,
1602 ¤t_version_major, ¤t_version_minor,
1603 ¤t_version_macro, ¤t_version_nano);
1605 _LOGE("Failed to compare current version(%d)", ret);
1606 return PMINFO_R_ERROR;
1609 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1610 target_version_minor, target_version_macro,
1611 target_version_nano, current_version_major,
1612 current_version_minor, current_version_macro,
1613 target_version_nano);
1615 if (target_version_major > current_version_major)
1616 *res = PMINFO_VERSION_NEW;
1617 else if (target_version_major < current_version_major)
1618 *res = PMINFO_VERSION_OLD;
1619 else if (target_version_minor > current_version_minor)
1620 *res = PMINFO_VERSION_NEW;
1621 else if (target_version_minor < current_version_minor)
1622 *res = PMINFO_VERSION_OLD;
1623 else if (target_version_macro > current_version_macro)
1624 *res = PMINFO_VERSION_NEW;
1625 else if (target_version_macro < current_version_macro)
1626 *res = PMINFO_VERSION_OLD;
1627 else if (target_version_nano > current_version_nano)
1628 *res = PMINFO_VERSION_NEW;
1629 else if (target_version_nano < current_version_nano)
1630 *res = PMINFO_VERSION_OLD;
1632 *res = PMINFO_VERSION_SAME;