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 "
178 privilege_x *privilege;
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) {
195 privilege = calloc(1, sizeof(privilege_x));
196 _save_column_str(stmt, 0, &privilege->value);
197 _save_column_str(stmt, 1, &privilege->type);
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, pi.external_path, "
301 "pi.package_support_mode";
302 static const char query_author[] =
303 ", pi.author_name, pi.author_email, pi.author_href";
304 static const char query_label[] =
306 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
307 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
308 static const char query_icon[] =
310 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
311 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
312 static const char query_description[] =
314 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
315 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
316 static const char query_from_clause[] = " FROM package_info as pi";
317 int ret = PMINFO_R_ERROR;
321 char *tmp_record = NULL;
322 char *constraints = NULL;
323 char query[MAX_QUERY_LEN] = { '\0' };
324 package_x *info = NULL;
325 author_x *author = NULL;
326 GList *bind_params = NULL;
329 pkgmgrinfo_filter_x *tmp_filter = NULL;
331 dbpath = getUserPkgParserDBPathUID(uid);
333 return PMINFO_R_ERROR;
335 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
336 if (ret != SQLITE_OK) {
337 _LOGD("failed to open db: %d", ret);
339 return PMINFO_R_ERROR;
343 if (filter != NULL) {
346 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
347 if (ret != PMINFO_R_OK) {
348 _LOGE("Failed to create filter");
349 return PMINFO_R_ERROR;
353 /* add package_disable='false' clause by default */
354 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
356 query_len = strlen(query_raw);
357 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
358 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
359 strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
360 query_len += strlen(query_author);
362 if (flag & PMINFO_PKGINFO_GET_LABEL) {
363 strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
364 query_len += strlen(query_label);
365 bind_params = g_list_append(bind_params, strdup(locale));
367 if (flag & PMINFO_PKGINFO_GET_ICON) {
368 strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
369 query_len += strlen(query_icon);
370 bind_params = g_list_append(bind_params, strdup(locale));
372 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
373 strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
374 query_len += strlen(query_description);
375 bind_params = g_list_append(bind_params, strdup(locale));
378 strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
379 query_len += strlen(query_from_clause);
381 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
382 if (ret != PMINFO_R_OK) {
383 LOGE("Failed to get WHERE clause");
388 strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
390 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
391 if (ret != SQLITE_OK) {
392 LOGE("prepare failed: %s", sqlite3_errmsg(db));
393 ret = PMINFO_R_ERROR;
397 ret = __bind_params(stmt, bind_params);
398 if (ret != SQLITE_OK) {
399 LOGE("Failed to bind parameters");
403 while (sqlite3_step(stmt) == SQLITE_ROW) {
404 info = calloc(1, sizeof(package_x));
406 LOGE("out of memory");
407 sqlite3_finalize(stmt);
408 sqlite3_close_v2(db);
409 return PMINFO_R_ERROR;
412 _save_column_str(stmt, idx++, &info->package);
413 if (g_hash_table_contains(packages,
414 (gconstpointer)info->package)) {
419 _save_column_str(stmt, idx++, &info->version);
420 _save_column_str(stmt, idx++, &info->installlocation);
421 _save_column_str(stmt, idx++, &info->removable);
422 _save_column_str(stmt, idx++, &info->preload);
423 _save_column_str(stmt, idx++, &info->readonly);
424 _save_column_str(stmt, idx++, &info->update);
425 _save_column_str(stmt, idx++, &info->appsetting);
426 _save_column_str(stmt, idx++, &info->system);
427 _save_column_str(stmt, idx++, &info->type);
428 _save_column_str(stmt, idx++, &info->package_size);
429 _save_column_str(stmt, idx++, &info->installed_time);
430 _save_column_str(stmt, idx++, &info->installed_storage);
431 _save_column_str(stmt, idx++, &info->storeclient_id);
432 _save_column_str(stmt, idx++, &info->mainapp_id);
433 _save_column_str(stmt, idx++, &info->package_url);
434 _save_column_str(stmt, idx++, &info->root_path);
435 _save_column_str(stmt, idx++, &info->csc_path);
436 _save_column_str(stmt, idx++, &info->nodisplay_setting);
437 _save_column_str(stmt, idx++, &info->api_version);
438 _save_column_str(stmt, idx++, &info->support_disable);
439 _save_column_str(stmt, idx++, &info->tep_name);
440 _save_column_str(stmt, idx++, &info->zip_mount_file);
441 _save_column_str(stmt, idx++, &info->external_path);
442 _save_column_str(stmt, idx++, &info->support_mode);
443 info->for_all_users =
444 strdup((uid != GLOBAL_USER) ? "false" : "true");
446 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
447 /* TODO : author should be retrieved at package_localized_info */
448 author = calloc(1, sizeof(author_x));
449 if (author == NULL) {
450 pkgmgrinfo_basic_free_package(info);
451 sqlite3_finalize(stmt);
452 sqlite3_close_v2(db);
453 return PMINFO_R_ERROR;
455 _save_column_str(stmt, idx++, &author->text);
456 _save_column_str(stmt, idx++, &author->email);
457 _save_column_str(stmt, idx++, &author->href);
458 info->author = g_list_append(info->author, author);
461 if (flag & PMINFO_PKGINFO_GET_LABEL) {
463 _save_column_str(stmt, idx++, &tmp_record);
465 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
466 pkgmgrinfo_basic_free_package(info);
467 sqlite3_finalize(stmt);
468 sqlite3_close_v2(db);
469 return PMINFO_R_ERROR;
473 if (flag & PMINFO_PKGINFO_GET_ICON) {
475 _save_column_str(stmt, idx++, &tmp_record);
476 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
477 pkgmgrinfo_basic_free_package(info);
478 sqlite3_finalize(stmt);
479 sqlite3_close_v2(db);
480 return PMINFO_R_ERROR;
484 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
486 _save_column_str(stmt, idx++, &tmp_record);
487 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
488 &info->description)) {
489 pkgmgrinfo_basic_free_package(info);
490 sqlite3_finalize(stmt);
491 sqlite3_close_v2(db);
492 return PMINFO_R_ERROR;
496 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
497 if (_pkginfo_get_privilege(db, info->package,
498 &info->privileges)) {
499 pkgmgrinfo_basic_free_package(info);
500 sqlite3_finalize(stmt);
501 sqlite3_close_v2(db);
502 return PMINFO_R_ERROR;
506 if (__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
507 ret = PMINFO_R_ERROR;
508 pkgmgrinfo_basic_free_package(info);
513 g_hash_table_insert(packages, (gpointer)info->package,
523 if (ret != PMINFO_R_OK && info != NULL)
524 pkgmgrinfo_basic_free_package(info);
527 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
529 g_list_free_full(bind_params, free);
530 sqlite3_close_v2(db);
531 sqlite3_finalize(stmt);
536 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
537 pkgmgrinfo_filter_x *filter, int flag,
538 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
543 pkgmgr_pkginfo_x info;
548 locale = _get_system_locale();
550 return PMINFO_R_ERROR;
552 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
556 return PMINFO_R_ERROR;
559 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
560 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
561 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
564 if (ret != PMINFO_R_OK) {
565 g_hash_table_destroy(list);
567 return PMINFO_R_ERROR;
570 g_hash_table_iter_init(&iter, list);
571 while (g_hash_table_iter_next(&iter, NULL, &value)) {
572 pkg = (package_x *)value;
575 info.locale = locale;
576 if (pkg_list_cb(&info, user_data) < 0)
580 g_hash_table_destroy(list);
586 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
587 pkgmgrinfo_pkginfo_h *handle)
592 pkgmgrinfo_pkginfo_filter_h filter;
593 pkgmgr_pkginfo_x *info;
595 if (pkgid == NULL || handle == NULL) {
596 LOGE("invalid parameter");
597 return PMINFO_R_EINVAL;
600 locale = _get_system_locale();
602 return PMINFO_R_ERROR;
604 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
605 if (ret != PMINFO_R_OK) {
610 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
611 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
612 if (ret != PMINFO_R_OK) {
613 pkgmgrinfo_pkginfo_filter_destroy(filter);
615 return PMINFO_R_ERROR;
618 list = g_hash_table_new(g_str_hash, g_str_equal);
620 pkgmgrinfo_pkginfo_filter_destroy(filter);
622 return PMINFO_R_ERROR;
625 ret = _pkginfo_get_packages(uid, locale, filter,
626 PMINFO_PKGINFO_GET_ALL, list);
627 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
628 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
629 PMINFO_PKGINFO_GET_ALL, list);
631 pkgmgrinfo_pkginfo_filter_destroy(filter);
632 if (ret != PMINFO_R_OK) {
633 g_hash_table_destroy(list);
638 if (!g_hash_table_size(list)) {
639 _LOGI("pkginfo for [%s] is not existed for user [%d]",
641 g_hash_table_destroy(list);
643 return PMINFO_R_ENOENT;
646 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
648 _LOGE("out of memory");
649 g_hash_table_destroy(list);
651 return PMINFO_R_ERROR;
655 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
656 info->locale = locale;
658 /* just free list only */
659 g_hash_table_destroy(list);
666 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
667 pkgmgrinfo_pkginfo_h *handle)
669 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
672 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
673 int flag, void *user_data, uid_t uid)
675 if (pkg_list_cb == NULL) {
676 LOGE("invalid parameter");
677 return PMINFO_R_EINVAL;
680 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
681 pkg_list_cb, user_data);
684 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
685 int flag, void *user_data)
687 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
688 user_data, _getuid());
691 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
692 void *user_data, uid_t uid)
694 if (pkg_list_cb == NULL) {
695 LOGE("invalid parameter");
696 return PMINFO_R_EINVAL;
699 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
700 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
703 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
706 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
710 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
712 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
714 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
715 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
717 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
718 return PMINFO_R_ERROR;
720 *pkg_name = (char *)info->pkg_info->package;
725 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
727 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
729 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
730 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
732 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
733 return PMINFO_R_ERROR;
735 *pkgid = (char *)info->pkg_info->package;
740 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
742 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
745 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
747 if (info->pkg_info == NULL)
748 return PMINFO_R_ERROR;
750 if (info->pkg_info->type == NULL)
753 *type = (char *)info->pkg_info->type;
758 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
760 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
762 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
763 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
765 if (info->pkg_info == NULL)
766 return PMINFO_R_ERROR;
768 if (info->pkg_info->version == NULL)
771 *version = (char *)info->pkg_info->version;
776 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
778 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
781 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
783 if (info->pkg_info == NULL)
784 return PMINFO_R_ERROR;
786 if (info->pkg_info->api_version == NULL)
789 *api_version = (char *)info->pkg_info->api_version;
794 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
796 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
798 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
799 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
801 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
802 return PMINFO_R_ERROR;
804 *tep_name = (char *)info->pkg_info->tep_name;
809 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
811 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
814 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
816 if (info->pkg_info == NULL)
817 return PMINFO_R_ERROR;
819 if (info->pkg_info->zip_mount_file == NULL)
820 *zip_mount_file = "";
822 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
827 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
830 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
833 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
835 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
836 return PMINFO_R_ERROR;
838 val = (char *)info->pkg_info->installlocation;
839 if (strcmp(val, "internal-only") == 0)
840 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
841 else if (strcmp(val, "prefer-external") == 0)
842 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
844 *location = PMINFO_INSTALL_LOCATION_AUTO;
849 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
851 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
854 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
855 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
857 if (info->pkg_info == NULL)
858 return PMINFO_R_ERROR;
860 if (info->pkg_info->package_size == NULL) {
863 _LOGE("out of memory");
864 return PMINFO_R_ERROR;
866 info->pkg_info->package_size = temp;
870 *size = atoi((char *)info->pkg_info->package_size);
875 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
878 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
881 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
883 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
884 return PMINFO_R_ERROR;
886 ptr = (icon_x *)info->pkg_info->icon->data;
888 return PMINFO_R_ERROR;
890 /* TODO : should we return empty string if there was no icon? */
891 if (ptr->text == NULL)
899 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
902 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
905 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
907 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
908 return PMINFO_R_ERROR;
910 ptr = (label_x *)info->pkg_info->label->data;
912 return PMINFO_R_ERROR;
914 /* TODO : should we return empty string if there was no label? */
915 if (ptr->text == NULL)
923 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
926 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
928 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
929 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
931 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
932 return PMINFO_R_ERROR;
934 ptr = (description_x *)info->pkg_info->description->data;
936 return PMINFO_R_ERROR;
938 if (ptr->text == NULL)
941 *description = (char *)ptr->text;
946 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
948 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
951 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
952 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
954 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
955 return PMINFO_R_ERROR;
957 author = (author_x *)info->pkg_info->author->data;
959 return PMINFO_R_ERROR;
961 if (author->text == NULL)
964 *author_name = (char *)author->text;
969 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
971 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
974 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
975 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
977 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
978 return PMINFO_R_ERROR;
980 author = (author_x *)info->pkg_info->author->data;
982 return PMINFO_R_ERROR;
984 if (author->email == NULL)
987 *author_email = (char *)author->email;
992 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
994 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
998 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1000 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1001 return PMINFO_R_ERROR;
1003 author = (author_x *)info->pkg_info->author->data;
1005 return PMINFO_R_ERROR;
1007 if (author->href == NULL)
1010 *author_href = (char *)author->href;
1015 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1017 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1020 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1022 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1023 return PMINFO_R_ERROR;
1025 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1026 *storage = PMINFO_INTERNAL_STORAGE;
1027 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1028 *storage = PMINFO_EXTERNAL_STORAGE;
1030 return PMINFO_R_ERROR;
1035 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1037 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1039 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1040 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1042 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1043 return PMINFO_R_ERROR;
1045 *installed_time = atoi(info->pkg_info->installed_time);
1050 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1052 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1055 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1057 if (info->pkg_info == NULL)
1058 return PMINFO_R_ERROR;
1060 if (info->pkg_info->storeclient_id == NULL)
1061 *storeclientid = "";
1063 *storeclientid = (char *)info->pkg_info->storeclient_id;
1068 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1070 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1072 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1073 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1075 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1076 return PMINFO_R_ERROR;
1078 *mainappid = (char *)info->pkg_info->mainapp_id;
1083 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1085 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1087 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1088 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1090 if (info->pkg_info == NULL)
1091 return PMINFO_R_ERROR;
1093 if (info->pkg_info->package_url == NULL)
1096 *url = (char *)info->pkg_info->package_url;
1101 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1103 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1106 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1108 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1109 return PMINFO_R_ERROR;
1111 *path = (char *)info->pkg_info->root_path;
1116 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1118 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1121 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1123 if (info->pkg_info == NULL)
1124 return PMINFO_R_ERROR;
1126 if (info->pkg_info->csc_path == NULL)
1129 *path = (char *)info->pkg_info->csc_path;
1134 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1136 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1137 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1139 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1140 if (info->pkg_info->support_mode)
1141 *support_mode = atoi(info->pkg_info->support_mode);
1148 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1151 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1153 #if 0 /* smack issue occured, check later */
1155 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1156 if (pkgid == NULL) {
1157 _LOGD("invalid func parameters\n");
1158 return PMINFO_R_ERROR;
1160 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1163 char app_mmc_path[FILENAME_MAX] = { 0, };
1164 char app_dir_path[FILENAME_MAX] = { 0, };
1165 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1166 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1167 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1168 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1170 /*check whether application is in external memory or not */
1171 fp = fopen(app_mmc_path, "r");
1173 _LOGD(" app path in external memory not accesible\n");
1178 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1182 /*check whether application is in internal or not */
1184 _LOGD(" app path in internal memory not accesible\n");
1186 return PMINFO_R_ERROR;
1189 /*check whether the application is installed in SD card
1190 but SD card is not present*/
1191 fp = fopen(app_mmc_internal_path, "r");
1194 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1198 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1203 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1210 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1212 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1214 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1215 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1217 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1218 return PMINFO_R_ERROR;
1220 *removable = _get_bool_value(info->pkg_info->removable);
1225 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1228 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1230 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1231 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1233 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1234 return PMINFO_R_ERROR;
1236 val = (char *)info->pkg_info->installlocation;
1237 if (strcmp(val, "internal-only") == 0)
1239 else if (strcmp(val, "prefer-external") == 0)
1247 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1249 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1251 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1252 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1254 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1255 return PMINFO_R_ERROR;
1257 *preload = _get_bool_value(info->pkg_info->preload);
1262 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1264 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1267 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1269 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1270 return PMINFO_R_ERROR;
1272 *system = _get_bool_value(info->pkg_info->system);
1277 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1279 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1282 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1284 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1285 return PMINFO_R_ERROR;
1287 *readonly = _get_bool_value(info->pkg_info->readonly);
1292 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1294 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1297 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1299 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1300 return PMINFO_R_ERROR;
1302 *update = _get_bool_value(info->pkg_info->update);
1307 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1309 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1312 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1314 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1315 return PMINFO_R_ERROR;
1317 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1322 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1324 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1327 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1329 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1330 return PMINFO_R_ERROR;
1332 *global = _get_bool_value(info->pkg_info->for_all_users);
1337 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1339 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1342 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1344 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1348 __cleanup_pkginfo(info);
1353 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1355 pkgmgrinfo_filter_x *filter;
1357 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1359 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1360 if (filter == NULL) {
1361 _LOGE("Out of Memory!!!");
1362 return PMINFO_R_ERROR;
1370 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1372 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1377 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1378 g_slist_free(filter->list);
1386 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1387 const char *property, const int value)
1389 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1393 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1394 pkgmgrinfo_node_x *node;
1396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1397 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1399 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1400 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1401 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1402 _LOGE("Invalid Integer Property\n");
1403 return PMINFO_R_EINVAL;
1405 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1407 _LOGE("Out of Memory!!!\n");
1408 return PMINFO_R_ERROR;
1410 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1411 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1413 _LOGE("Out of Memory\n");
1415 return PMINFO_R_ERROR;
1419 /*If API is called multiple times for same property, we should override the previous values.
1420 Last value set will be used for filtering.*/
1421 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1423 filter->list = g_slist_delete_link(filter->list, link);
1424 filter->list = g_slist_append(filter->list, (gpointer)node);
1429 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1430 const char *property, const bool value)
1435 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1436 pkgmgrinfo_node_x *node;
1438 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1439 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1441 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1442 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1443 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1444 _LOGE("Invalid Boolean Property\n");
1445 return PMINFO_R_EINVAL;
1447 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1449 _LOGE("Out of Memory!!!\n");
1450 return PMINFO_R_ERROR;
1453 val = strndup("true", 4);
1455 val = strndup("false", 5);
1457 _LOGE("Out of Memory\n");
1459 return PMINFO_R_ERROR;
1463 /*If API is called multiple times for same property, we should override the previous values.
1464 Last value set will be used for filtering.*/
1465 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1467 filter->list = g_slist_delete_link(filter->list, link);
1468 filter->list = g_slist_append(filter->list, (gpointer)node);
1473 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1474 const char *property, const char *value)
1479 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1480 pkgmgrinfo_node_x *node;
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1483 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1484 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1486 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1487 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1488 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1489 _LOGE("Invalid String Property\n");
1490 return PMINFO_R_EINVAL;
1492 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1494 _LOGE("Out of Memory!!!\n");
1495 return PMINFO_R_ERROR;
1497 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1498 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1499 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1500 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1501 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1502 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1503 else if (strcmp(value, "installed_internal") == 0)
1504 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1505 else if (strcmp(value, "installed_external") == 0)
1506 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1508 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1510 _LOGE("Out of Memory\n");
1512 return PMINFO_R_ERROR;
1516 /*If API is called multiple times for same property, we should override the previous values.
1517 Last value set will be used for filtering.*/
1518 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1520 filter->list = g_slist_delete_link(filter->list, link);
1521 filter->list = g_slist_append(filter->list, (gpointer)node);
1526 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1530 GHashTable *list = NULL;
1532 if (handle == NULL || count == NULL) {
1533 _LOGE("invalid parameter");
1534 return PMINFO_R_EINVAL;
1537 locale = _get_system_locale();
1539 return PMINFO_R_ERROR;
1541 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1545 return PMINFO_R_ERROR;
1548 ret = _pkginfo_get_packages(uid, locale,
1549 (pkgmgrinfo_filter_x *)handle, 0, list);
1550 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1551 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1554 if (ret != PMINFO_R_OK) {
1555 g_hash_table_destroy(list);
1557 return PMINFO_R_ERROR;
1560 *count = g_hash_table_size(list);
1562 g_hash_table_destroy(list);
1568 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1570 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1573 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1574 pkgmgrinfo_pkginfo_filter_h handle,
1575 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1577 if (handle == NULL || pkg_cb == NULL) {
1578 LOGE("invalid parameter");
1579 return PMINFO_R_EINVAL;
1582 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1583 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1586 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1587 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1589 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1592 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1593 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1595 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1596 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1598 privilege_x *privilege;
1600 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1602 if (info->pkg_info == NULL)
1603 return PMINFO_R_ERROR;
1605 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1606 privilege = (privilege_x *)tmp->data;
1607 if (privilege == NULL)
1609 ret = privilege_func(privilege->value, user_data);