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 "pkgmgr_parser.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_private.h"
41 #include "pkgmgrinfo_debug.h"
42 #include "pkgmgr-info.h"
43 #include "pkgmgr_parser_db.h"
44 #include "pkgmgr_parser_internal.h"
46 static bool _get_bool_value(const char *str)
48 if (str && !strcmp(str, "true"))
54 static gint __compare_func(gconstpointer data1, gconstpointer data2)
56 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
57 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
58 if (node1->prop == node2->prop)
60 else if (node1->prop > node2->prop)
66 static void __destroy_each_node(gpointer data, gpointer user_data)
69 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
82 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
86 free((void *)data->locale);
90 pkgmgrinfo_basic_free_package(data->pkg_info);
96 long long _pkgmgr_calculate_dir_size(char *dirname)
100 int q = 0; /*quotient*/
101 int r = 0; /*remainder*/
103 struct dirent ep, *result;
104 struct stat fileinfo;
105 char abs_filename[FILENAME_MAX] = { 0, };
106 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
108 dp = opendir(dirname);
110 _LOGE("Couldn't open the directory\n");
114 for (ret = readdir_r(dp, &ep, &result);
115 ret == 0 && result != NULL;
116 ret = readdir_r(dp, &ep, &result)) {
117 if (!strcmp(ep.d_name, ".") ||
118 !strcmp(ep.d_name, "..")) {
121 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
123 if (lstat(abs_filename, &fileinfo) < 0)
124 perror(abs_filename);
126 if (S_ISDIR(fileinfo.st_mode)) {
127 total += fileinfo.st_size;
128 if (strcmp(ep.d_name, ".")
129 && strcmp(ep.d_name, "..")) {
130 ret = _pkgmgr_calculate_dir_size
134 } else if (S_ISLNK(fileinfo.st_mode)) {
137 /*It is a file. Calculate the actual
138 size occupied (in terms of 4096 blocks)*/
139 q = (fileinfo.st_size / BLOCK_SIZE);
140 r = (fileinfo.st_size % BLOCK_SIZE);
143 total += q * BLOCK_SIZE;
152 static int _pkginfo_add_description_info_into_list(const char *locale,
153 char *record, GList **description)
157 info = calloc(1, sizeof(description_x));
159 LOGE("out of memory");
160 return PMINFO_R_ERROR;
162 info->lang = strdup(locale);
164 *description = g_list_append(*description, info);
169 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
172 static const char query_raw[] =
173 "SELECT DISTINCT privilege FROM package_privilege_info "
180 query = sqlite3_mprintf(query_raw, pkgid);
182 LOGE("out of memory");
183 return PMINFO_R_ERROR;
186 ret = sqlite3_prepare_v2(db, query, strlen(query),
189 if (ret != SQLITE_OK) {
190 LOGE("prepare failed: %s", sqlite3_errmsg(db));
191 return PMINFO_R_ERROR;
194 while (sqlite3_step(stmt) == SQLITE_ROW) {
196 _save_column_str(stmt, 0, &privilege);
198 *privileges = g_list_append(*privileges,
199 (gpointer)privilege);
202 sqlite3_finalize(stmt);
207 static const char join_localized_info[] =
208 " LEFT OUTER JOIN package_localized_info"
209 " ON pi.package=package_localized_info.package"
210 " AND package_localized_info.package_locale=?";
211 static const char join_privilege_info[] =
212 " LEFT OUTER JOIN package_privilege_info"
213 " ON pi.package=package_privilege_info.package";
215 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
216 const char *locale, char **query, GList **bind_params)
219 char buf[MAX_QUERY_LEN] = { '\0' };
220 char buf2[MAX_QUERY_LEN] = { '\0' };
221 char *condition = NULL;
228 len += strlen(" WHERE 1=1 ");
229 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
230 for (list = filter->list; list; list = list->next) {
231 joined |= __get_filter_condition(list->data, &condition,
233 if (condition == NULL)
236 len += strlen(" AND ");
237 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
239 len += strlen(condition);
240 strncat(buf, condition, sizeof(buf) - len - 1);
245 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
246 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
247 len += strlen(join_localized_info);
248 *bind_params = g_list_append(*bind_params, strdup(locale));
250 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
251 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
252 len += strlen(join_privilege_info);
254 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
256 *query = strdup(buf2);
258 return PMINFO_R_ERROR;
263 static void __free_packages(gpointer data)
265 pkgmgrinfo_basic_free_package((package_x *)data);
268 static int __bind_params(sqlite3_stmt *stmt, GList *params)
270 GList *tmp_list = NULL;
274 if (stmt == NULL || params == NULL)
275 return PMINFO_R_EINVAL;
279 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
280 if (ret != SQLITE_OK)
281 return PMINFO_R_ERROR;
282 tmp_list = tmp_list->next;
288 static int _pkginfo_get_packages(uid_t uid, const char *locale,
289 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
291 static const char query_raw[] =
292 "SELECT DISTINCT pi.package, pi.package_version, "
293 "pi.install_location, pi.package_removable, "
294 "pi.package_preload, pi.package_readonly, pi.package_update, "
295 "pi.package_appsetting, pi.package_system, pi.package_type, "
296 "pi.package_size, pi.installed_time, pi.installed_storage, "
297 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
298 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
299 "pi.package_api_version, pi.package_support_disable, "
300 "pi.package_tep_name, pi.package_zip_mount_file";
301 static const char query_author[] =
302 ", pi.author_name, pi.author_email, pi.author_href";
303 static const char query_label[] =
305 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
306 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
307 static const char query_icon[] =
309 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
310 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
311 static const char query_description[] =
313 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
314 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
315 static const char query_from_clause[] = " FROM package_info as pi";
316 int ret = PMINFO_R_ERROR;
320 char *tmp_record = NULL;
321 char *constraints = NULL;
322 char query[MAX_QUERY_LEN] = { '\0' };
323 package_x *info = NULL;
324 author_x *author = NULL;
325 GList *bind_params = NULL;
328 pkgmgrinfo_filter_x *tmp_filter = NULL;
330 dbpath = getUserPkgParserDBPathUID(uid);
332 return PMINFO_R_ERROR;
334 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
335 if (ret != SQLITE_OK) {
336 _LOGD("failed to open db: %d", ret);
338 return PMINFO_R_ERROR;
342 if (filter != NULL) {
345 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
346 if (ret != PMINFO_R_OK) {
347 _LOGE("Failed to create filter");
348 return PMINFO_R_ERROR;
352 /* add package_disable='false' clause by default */
353 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
355 query_len = strlen(query_raw);
356 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
357 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
358 strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
359 query_len += strlen(query_author);
361 if (flag & PMINFO_PKGINFO_GET_LABEL) {
362 strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
363 query_len += strlen(query_label);
364 bind_params = g_list_append(bind_params, strdup(locale));
366 if (flag & PMINFO_PKGINFO_GET_ICON) {
367 strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
368 query_len += strlen(query_icon);
369 bind_params = g_list_append(bind_params, strdup(locale));
371 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
372 strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
373 query_len += strlen(query_description);
374 bind_params = g_list_append(bind_params, strdup(locale));
377 strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
378 query_len += strlen(query_from_clause);
380 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
381 if (ret != PMINFO_R_OK) {
382 LOGE("Failed to get WHERE clause");
387 strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
389 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
390 if (ret != SQLITE_OK) {
391 LOGE("prepare failed: %s", sqlite3_errmsg(db));
392 ret = PMINFO_R_ERROR;
396 ret = __bind_params(stmt, bind_params);
397 if (ret != SQLITE_OK) {
398 LOGE("Failed to bind parameters");
402 while (sqlite3_step(stmt) == SQLITE_ROW) {
403 info = calloc(1, sizeof(package_x));
405 LOGE("out of memory");
406 sqlite3_finalize(stmt);
407 sqlite3_close_v2(db);
408 return PMINFO_R_ERROR;
411 _save_column_str(stmt, idx++, &info->package);
412 if (g_hash_table_contains(packages,
413 (gconstpointer)info->package)) {
418 _save_column_str(stmt, idx++, &info->version);
419 _save_column_str(stmt, idx++, &info->installlocation);
420 _save_column_str(stmt, idx++, &info->removable);
421 _save_column_str(stmt, idx++, &info->preload);
422 _save_column_str(stmt, idx++, &info->readonly);
423 _save_column_str(stmt, idx++, &info->update);
424 _save_column_str(stmt, idx++, &info->appsetting);
425 _save_column_str(stmt, idx++, &info->system);
426 _save_column_str(stmt, idx++, &info->type);
427 _save_column_str(stmt, idx++, &info->package_size);
428 _save_column_str(stmt, idx++, &info->installed_time);
429 _save_column_str(stmt, idx++, &info->installed_storage);
430 _save_column_str(stmt, idx++, &info->storeclient_id);
431 _save_column_str(stmt, idx++, &info->mainapp_id);
432 _save_column_str(stmt, idx++, &info->package_url);
433 _save_column_str(stmt, idx++, &info->root_path);
434 _save_column_str(stmt, idx++, &info->csc_path);
435 _save_column_str(stmt, idx++, &info->nodisplay_setting);
436 _save_column_str(stmt, idx++, &info->api_version);
437 _save_column_str(stmt, idx++, &info->support_disable);
438 _save_column_str(stmt, idx++, &info->tep_name);
439 _save_column_str(stmt, idx++, &info->zip_mount_file);
440 info->for_all_users =
441 strdup((uid != GLOBAL_USER) ? "false" : "true");
443 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
444 /* TODO : author should be retrieved at package_localized_info */
445 author = calloc(1, sizeof(author_x));
446 if (author == NULL) {
447 pkgmgrinfo_basic_free_package(info);
448 sqlite3_finalize(stmt);
449 sqlite3_close_v2(db);
450 return PMINFO_R_ERROR;
452 _save_column_str(stmt, idx++, &author->text);
453 _save_column_str(stmt, idx++, &author->email);
454 _save_column_str(stmt, idx++, &author->href);
455 info->author = g_list_append(info->author, author);
458 if (flag & PMINFO_PKGINFO_GET_LABEL) {
460 _save_column_str(stmt, idx++, &tmp_record);
462 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
463 pkgmgrinfo_basic_free_package(info);
464 sqlite3_finalize(stmt);
465 sqlite3_close_v2(db);
466 return PMINFO_R_ERROR;
470 if (flag & PMINFO_PKGINFO_GET_ICON) {
472 _save_column_str(stmt, idx++, &tmp_record);
473 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
474 pkgmgrinfo_basic_free_package(info);
475 sqlite3_finalize(stmt);
476 sqlite3_close_v2(db);
477 return PMINFO_R_ERROR;
481 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
483 _save_column_str(stmt, idx++, &tmp_record);
484 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
485 &info->description)) {
486 pkgmgrinfo_basic_free_package(info);
487 sqlite3_finalize(stmt);
488 sqlite3_close_v2(db);
489 return PMINFO_R_ERROR;
493 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
494 if (_pkginfo_get_privilege(db, info->package,
495 &info->privileges)) {
496 pkgmgrinfo_basic_free_package(info);
497 sqlite3_finalize(stmt);
498 sqlite3_close_v2(db);
499 return PMINFO_R_ERROR;
503 g_hash_table_insert(packages, (gpointer)info->package,
513 if (ret != PMINFO_R_OK && info != NULL)
514 pkgmgrinfo_basic_free_package(info);
517 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
519 g_list_free_full(bind_params, free);
520 sqlite3_close_v2(db);
521 sqlite3_finalize(stmt);
526 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
527 pkgmgrinfo_filter_x *filter, int flag,
528 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
533 pkgmgr_pkginfo_x info;
538 locale = _get_system_locale();
540 return PMINFO_R_ERROR;
542 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
546 return PMINFO_R_ERROR;
549 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
550 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
551 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
554 if (ret != PMINFO_R_OK) {
555 g_hash_table_destroy(list);
557 return PMINFO_R_ERROR;
560 g_hash_table_iter_init(&iter, list);
561 while (g_hash_table_iter_next(&iter, NULL, &value)) {
562 pkg = (package_x *)value;
565 info.locale = locale;
566 if (pkg_list_cb(&info, user_data) < 0)
570 g_hash_table_destroy(list);
576 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
577 pkgmgrinfo_pkginfo_h *handle)
582 pkgmgrinfo_pkginfo_filter_h filter;
583 pkgmgr_pkginfo_x *info;
585 if (pkgid == NULL || handle == NULL) {
586 LOGE("invalid parameter");
587 return PMINFO_R_EINVAL;
590 locale = _get_system_locale();
592 return PMINFO_R_ERROR;
594 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
595 if (ret != PMINFO_R_OK) {
600 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
601 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
602 if (ret != PMINFO_R_OK) {
603 pkgmgrinfo_pkginfo_filter_destroy(filter);
605 return PMINFO_R_ERROR;
608 list = g_hash_table_new(g_str_hash, g_str_equal);
610 pkgmgrinfo_pkginfo_filter_destroy(filter);
612 return PMINFO_R_ERROR;
615 ret = _pkginfo_get_packages(uid, locale, filter,
616 PMINFO_PKGINFO_GET_ALL, list);
617 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
618 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
619 PMINFO_PKGINFO_GET_ALL, list);
621 pkgmgrinfo_pkginfo_filter_destroy(filter);
622 if (ret != PMINFO_R_OK) {
623 g_hash_table_destroy(list);
628 if (!g_hash_table_size(list)) {
629 _LOGI("pkginfo for [%s] is not existed for user [%d]",
631 g_hash_table_destroy(list);
633 return PMINFO_R_ENOENT;
636 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
638 _LOGE("out of memory");
639 g_hash_table_destroy(list);
641 return PMINFO_R_ERROR;
645 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
646 info->locale = locale;
648 /* just free list only */
649 g_hash_table_destroy(list);
656 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
657 pkgmgrinfo_pkginfo_h *handle)
659 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
662 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
663 int flag, void *user_data, uid_t uid)
665 if (pkg_list_cb == NULL) {
666 LOGE("invalid parameter");
667 return PMINFO_R_EINVAL;
670 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
671 pkg_list_cb, user_data);
674 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
675 int flag, void *user_data)
677 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
678 user_data, _getuid());
681 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
682 void *user_data, uid_t uid)
684 if (pkg_list_cb == NULL) {
685 LOGE("invalid parameter");
686 return PMINFO_R_EINVAL;
689 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
690 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
693 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
696 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
700 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
702 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
705 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
707 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
708 return PMINFO_R_ERROR;
710 *pkg_name = (char *)info->pkg_info->package;
715 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
717 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
720 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
722 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
723 return PMINFO_R_ERROR;
725 *pkgid = (char *)info->pkg_info->package;
730 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
732 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
734 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
735 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
737 if (info->pkg_info == NULL)
738 return PMINFO_R_ERROR;
740 if (info->pkg_info->type == NULL)
743 *type = (char *)info->pkg_info->type;
748 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
750 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
752 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
753 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
755 if (info->pkg_info == NULL)
756 return PMINFO_R_ERROR;
758 if (info->pkg_info->version == NULL)
761 *version = (char *)info->pkg_info->version;
766 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
768 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
770 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
771 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
773 if (info->pkg_info == NULL)
774 return PMINFO_R_ERROR;
776 if (info->pkg_info->api_version == NULL)
779 *api_version = (char *)info->pkg_info->api_version;
784 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
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(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
791 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
792 return PMINFO_R_ERROR;
794 *tep_name = (char *)info->pkg_info->tep_name;
799 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
801 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
803 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
804 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
806 if (info->pkg_info == NULL)
807 return PMINFO_R_ERROR;
809 if (info->pkg_info->zip_mount_file == NULL)
810 *zip_mount_file = "";
812 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
817 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
820 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
822 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
823 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
825 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
826 return PMINFO_R_ERROR;
828 val = (char *)info->pkg_info->installlocation;
829 if (strcmp(val, "internal-only") == 0)
830 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
831 else if (strcmp(val, "prefer-external") == 0)
832 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
834 *location = PMINFO_INSTALL_LOCATION_AUTO;
839 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
841 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
845 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
847 if (info->pkg_info == NULL)
848 return PMINFO_R_ERROR;
850 if (info->pkg_info->package_size == NULL) {
853 _LOGE("out of memory");
854 return PMINFO_R_ERROR;
856 info->pkg_info->package_size = temp;
860 *size = atoi((char *)info->pkg_info->package_size);
865 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
868 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
870 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
871 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
873 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
874 return PMINFO_R_ERROR;
876 ptr = (icon_x *)info->pkg_info->icon->data;
878 return PMINFO_R_ERROR;
880 /* TODO : should we return empty string if there was no icon? */
881 if (ptr->text == NULL)
889 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
892 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
895 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
897 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
898 return PMINFO_R_ERROR;
900 ptr = (label_x *)info->pkg_info->label->data;
902 return PMINFO_R_ERROR;
904 /* TODO : should we return empty string if there was no label? */
905 if (ptr->text == NULL)
913 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
916 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
919 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
921 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
922 return PMINFO_R_ERROR;
924 ptr = (description_x *)info->pkg_info->description->data;
926 return PMINFO_R_ERROR;
928 if (ptr->text == NULL)
931 *description = (char *)ptr->text;
936 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
938 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
942 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
944 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
945 return PMINFO_R_ERROR;
947 author = (author_x *)info->pkg_info->author->data;
949 return PMINFO_R_ERROR;
951 if (author->text == NULL)
954 *author_name = (char *)author->text;
959 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
961 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
964 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
965 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
967 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
968 return PMINFO_R_ERROR;
970 author = (author_x *)info->pkg_info->author->data;
972 return PMINFO_R_ERROR;
974 if (author->email == NULL)
977 *author_email = (char *)author->email;
982 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
984 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
987 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
988 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
990 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
991 return PMINFO_R_ERROR;
993 author = (author_x *)info->pkg_info->author->data;
995 return PMINFO_R_ERROR;
997 if (author->href == NULL)
1000 *author_href = (char *)author->href;
1005 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1007 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1010 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1012 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1013 return PMINFO_R_ERROR;
1015 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1016 *storage = PMINFO_INTERNAL_STORAGE;
1017 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1018 *storage = PMINFO_EXTERNAL_STORAGE;
1020 return PMINFO_R_ERROR;
1025 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1027 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1029 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1030 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1032 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1033 return PMINFO_R_ERROR;
1035 *installed_time = atoi(info->pkg_info->installed_time);
1040 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1042 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1044 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1045 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1047 if (info->pkg_info == NULL)
1048 return PMINFO_R_ERROR;
1050 if (info->pkg_info->storeclient_id == NULL)
1051 *storeclientid = "";
1053 *storeclientid = (char *)info->pkg_info->storeclient_id;
1058 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
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(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1065 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1066 return PMINFO_R_ERROR;
1068 *mainappid = (char *)info->pkg_info->mainapp_id;
1073 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
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(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1080 if (info->pkg_info == NULL)
1081 return PMINFO_R_ERROR;
1083 if (info->pkg_info->package_url == NULL)
1086 *url = (char *)info->pkg_info->package_url;
1091 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
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(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1098 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1099 return PMINFO_R_ERROR;
1101 *path = (char *)info->pkg_info->root_path;
1106 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1108 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1110 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1111 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1113 if (info->pkg_info == NULL)
1114 return PMINFO_R_ERROR;
1116 if (info->pkg_info->csc_path == NULL)
1119 *path = (char *)info->pkg_info->csc_path;
1125 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1128 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1130 #if 0 /* smack issue occured, check later */
1132 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1133 if (pkgid == NULL) {
1134 _LOGD("invalid func parameters\n");
1135 return PMINFO_R_ERROR;
1137 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1140 char app_mmc_path[FILENAME_MAX] = { 0, };
1141 char app_dir_path[FILENAME_MAX] = { 0, };
1142 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1143 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1144 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1145 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1147 /*check whether application is in external memory or not */
1148 fp = fopen(app_mmc_path, "r");
1150 _LOGD(" app path in external memory not accesible\n");
1155 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1159 /*check whether application is in internal or not */
1161 _LOGD(" app path in internal memory not accesible\n");
1163 return PMINFO_R_ERROR;
1166 /*check whether the application is installed in SD card
1167 but SD card is not present*/
1168 fp = fopen(app_mmc_internal_path, "r");
1171 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1175 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1180 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1187 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1189 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1192 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1194 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1195 return PMINFO_R_ERROR;
1197 *removable = _get_bool_value(info->pkg_info->removable);
1202 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1205 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1208 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1210 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1211 return PMINFO_R_ERROR;
1213 val = (char *)info->pkg_info->installlocation;
1214 if (strcmp(val, "internal-only") == 0)
1216 else if (strcmp(val, "prefer-external") == 0)
1224 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1226 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1228 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1229 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1231 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1232 return PMINFO_R_ERROR;
1234 *preload = _get_bool_value(info->pkg_info->preload);
1239 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1241 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1243 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1244 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1246 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1247 return PMINFO_R_ERROR;
1249 *system = _get_bool_value(info->pkg_info->system);
1254 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1256 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1258 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1259 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1261 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1262 return PMINFO_R_ERROR;
1264 *readonly = _get_bool_value(info->pkg_info->readonly);
1269 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1271 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1274 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1276 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1277 return PMINFO_R_ERROR;
1279 *update = _get_bool_value(info->pkg_info->update);
1284 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1286 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1289 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1291 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1292 return PMINFO_R_ERROR;
1294 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1299 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1301 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1303 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1304 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1306 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1307 return PMINFO_R_ERROR;
1309 *global = _get_bool_value(info->pkg_info->for_all_users);
1314 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1316 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1319 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1321 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1325 __cleanup_pkginfo(info);
1330 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1332 pkgmgrinfo_filter_x *filter;
1334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1336 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1337 if (filter == NULL) {
1338 _LOGE("Out of Memory!!!");
1339 return PMINFO_R_ERROR;
1347 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1349 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1351 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1354 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1355 g_slist_free(filter->list);
1363 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1364 const char *property, const int value)
1366 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1370 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1371 pkgmgrinfo_node_x *node;
1373 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1374 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1376 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1377 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1378 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1379 _LOGE("Invalid Integer Property\n");
1380 return PMINFO_R_EINVAL;
1382 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1384 _LOGE("Out of Memory!!!\n");
1385 return PMINFO_R_ERROR;
1387 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1388 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1390 _LOGE("Out of Memory\n");
1392 return PMINFO_R_ERROR;
1396 /*If API is called multiple times for same property, we should override the previous values.
1397 Last value set will be used for filtering.*/
1398 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1400 filter->list = g_slist_delete_link(filter->list, link);
1401 filter->list = g_slist_append(filter->list, (gpointer)node);
1406 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1407 const char *property, const bool value)
1412 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1413 pkgmgrinfo_node_x *node;
1415 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1416 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1418 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1419 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1420 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1421 _LOGE("Invalid Boolean Property\n");
1422 return PMINFO_R_EINVAL;
1424 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1426 _LOGE("Out of Memory!!!\n");
1427 return PMINFO_R_ERROR;
1430 val = strndup("true", 4);
1432 val = strndup("false", 5);
1434 _LOGE("Out of Memory\n");
1436 return PMINFO_R_ERROR;
1440 /*If API is called multiple times for same property, we should override the previous values.
1441 Last value set will be used for filtering.*/
1442 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1444 filter->list = g_slist_delete_link(filter->list, link);
1445 filter->list = g_slist_append(filter->list, (gpointer)node);
1450 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1451 const char *property, const char *value)
1456 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1457 pkgmgrinfo_node_x *node;
1459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1460 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1461 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1463 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1464 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1465 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1466 _LOGE("Invalid String Property\n");
1467 return PMINFO_R_EINVAL;
1469 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1471 _LOGE("Out of Memory!!!\n");
1472 return PMINFO_R_ERROR;
1474 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1475 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1476 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1477 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1478 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1479 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1480 else if (strcmp(value, "installed_internal") == 0)
1481 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1482 else if (strcmp(value, "installed_external") == 0)
1483 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1485 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1487 _LOGE("Out of Memory\n");
1489 return PMINFO_R_ERROR;
1493 /*If API is called multiple times for same property, we should override the previous values.
1494 Last value set will be used for filtering.*/
1495 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1497 filter->list = g_slist_delete_link(filter->list, link);
1498 filter->list = g_slist_append(filter->list, (gpointer)node);
1503 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1507 GHashTable *list = NULL;
1509 if (handle == NULL || count == NULL) {
1510 _LOGE("invalid parameter");
1511 return PMINFO_R_EINVAL;
1514 locale = _get_system_locale();
1516 return PMINFO_R_ERROR;
1518 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1522 return PMINFO_R_ERROR;
1525 ret = _pkginfo_get_packages(uid, locale,
1526 (pkgmgrinfo_filter_x *)handle, 0, list);
1527 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1528 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1531 if (ret != PMINFO_R_OK) {
1532 g_hash_table_destroy(list);
1534 return PMINFO_R_ERROR;
1537 *count = g_hash_table_size(list);
1539 g_hash_table_destroy(list);
1545 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1547 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1550 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1551 pkgmgrinfo_pkginfo_filter_h handle,
1552 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1554 if (handle == NULL || pkg_cb == NULL) {
1555 LOGE("invalid parameter");
1556 return PMINFO_R_EINVAL;
1559 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1560 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1563 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1564 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1566 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1569 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1570 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1572 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1573 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1575 const char *privilege;
1577 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1579 if (info->pkg_info == NULL)
1580 return PMINFO_R_ERROR;
1582 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1583 privilege = (const char *)tmp->data;
1584 if (privilege == NULL)
1586 ret = privilege_func(privilege, user_data);