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"
43 static bool _get_bool_value(const char *str)
45 if (str && !strcmp(str, "true"))
51 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
54 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
55 if (node1->prop == node2->prop)
57 else if (node1->prop > node2->prop)
63 static void __destroy_each_node(gpointer data, gpointer user_data)
66 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
79 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
83 free((void *)data->locale);
87 pkgmgrinfo_basic_free_package(data->pkg_info);
93 long long _pkgmgr_calculate_dir_size(char *dirname)
97 int q = 0; /*quotient*/
98 int r = 0; /*remainder*/
100 struct dirent ep, *result;
101 struct stat fileinfo;
102 char abs_filename[FILENAME_MAX] = { 0, };
103 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
105 dp = opendir(dirname);
107 _LOGE("Couldn't open the directory\n");
111 for (ret = readdir_r(dp, &ep, &result);
112 ret == 0 && result != NULL;
113 ret = readdir_r(dp, &ep, &result)) {
114 if (!strcmp(ep.d_name, ".") ||
115 !strcmp(ep.d_name, "..")) {
118 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
120 if (lstat(abs_filename, &fileinfo) < 0)
121 perror(abs_filename);
123 if (S_ISDIR(fileinfo.st_mode)) {
124 total += fileinfo.st_size;
125 if (strcmp(ep.d_name, ".")
126 && strcmp(ep.d_name, "..")) {
127 ret = _pkgmgr_calculate_dir_size
131 } else if (S_ISLNK(fileinfo.st_mode)) {
134 /*It is a file. Calculate the actual
135 size occupied (in terms of 4096 blocks)*/
136 q = (fileinfo.st_size / BLOCK_SIZE);
137 r = (fileinfo.st_size % BLOCK_SIZE);
140 total += q * BLOCK_SIZE;
149 static int _pkginfo_add_description_info_into_list(const char *locale,
150 char *record, GList **description)
154 info = calloc(1, sizeof(description_x));
156 LOGE("out of memory");
157 return PMINFO_R_ERROR;
159 info->lang = strdup(locale);
161 *description = g_list_append(*description, info);
166 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
169 static const char query_raw[] =
170 "SELECT DISTINCT privilege FROM package_privilege_info "
175 privilege_x *privilege;
177 query = sqlite3_mprintf(query_raw, pkgid);
179 LOGE("out of memory");
180 return PMINFO_R_ERROR;
183 ret = sqlite3_prepare_v2(db, query, strlen(query),
186 if (ret != SQLITE_OK) {
187 LOGE("prepare failed: %s", sqlite3_errmsg(db));
188 return PMINFO_R_ERROR;
191 while (sqlite3_step(stmt) == SQLITE_ROW) {
192 privilege = calloc(1, sizeof(privilege_x));
193 _save_column_str(stmt, 0, &privilege->value);
194 _save_column_str(stmt, 1, &privilege->type);
195 *privileges = g_list_append(*privileges,
196 (gpointer)privilege);
199 sqlite3_finalize(stmt);
204 static const char join_localized_info[] =
205 " LEFT OUTER JOIN package_localized_info"
206 " ON pi.package=package_localized_info.package"
207 " AND package_localized_info.package_locale=?";
208 static const char join_privilege_info[] =
209 " LEFT OUTER JOIN package_privilege_info"
210 " ON pi.package=package_privilege_info.package";
212 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
213 const char *locale, char **query, GList **bind_params)
216 char buf[MAX_QUERY_LEN] = { '\0' };
217 char buf2[MAX_QUERY_LEN] = { '\0' };
218 char *condition = NULL;
225 len += strlen(" WHERE 1=1 ");
226 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
227 for (list = filter->list; list; list = list->next) {
228 joined |= __get_filter_condition(list->data, &condition,
230 if (condition == NULL)
233 len += strlen(" AND ");
234 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
236 len += strlen(condition);
237 strncat(buf, condition, sizeof(buf) - len - 1);
242 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
243 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
244 len += strlen(join_localized_info);
245 *bind_params = g_list_append(*bind_params, strdup(locale));
247 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
248 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
249 len += strlen(join_privilege_info);
251 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
253 *query = strdup(buf2);
255 return PMINFO_R_ERROR;
260 static void __free_packages(gpointer data)
262 pkgmgrinfo_basic_free_package((package_x *)data);
265 static int __bind_params(sqlite3_stmt *stmt, GList *params)
267 GList *tmp_list = NULL;
271 if (stmt == NULL || params == NULL)
272 return PMINFO_R_EINVAL;
276 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
277 if (ret != SQLITE_OK)
278 return PMINFO_R_ERROR;
279 tmp_list = tmp_list->next;
285 static int _pkginfo_get_packages(uid_t uid, const char *locale,
286 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
288 static const char query_raw[] =
289 "SELECT DISTINCT pi.package, pi.package_version, "
290 "pi.install_location, pi.package_removable, "
291 "pi.package_preload, pi.package_readonly, pi.package_update, "
292 "pi.package_appsetting, pi.package_system, pi.package_type, "
293 "pi.package_size, pi.installed_time, pi.installed_storage, "
294 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
295 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
296 "pi.package_api_version, pi.package_support_disable, "
297 "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, "
298 "pi.package_support_mode";
299 static const char query_author[] =
300 ", pi.author_name, pi.author_email, pi.author_href";
301 static const char query_label[] =
303 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
304 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
305 static const char query_icon[] =
307 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
308 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
309 static const char query_description[] =
311 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
312 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
313 static const char query_from_clause[] = " FROM package_info as pi";
314 int ret = PMINFO_R_ERROR;
318 char *tmp_record = NULL;
319 char *constraints = NULL;
320 char query[MAX_QUERY_LEN] = { '\0' };
321 package_x *info = NULL;
322 author_x *author = NULL;
323 GList *bind_params = NULL;
326 pkgmgrinfo_filter_x *tmp_filter = NULL;
328 dbpath = getUserPkgParserDBPathUID(uid);
330 return PMINFO_R_ERROR;
332 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
333 if (ret != SQLITE_OK) {
334 _LOGD("failed to open db: %d", ret);
336 return PMINFO_R_ERROR;
340 if (filter != NULL) {
343 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
344 if (ret != PMINFO_R_OK) {
345 _LOGE("Failed to create filter");
346 return PMINFO_R_ERROR;
350 /* add package_disable='false' clause by default */
351 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
353 query_len = strlen(query_raw);
354 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
355 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
356 strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
357 query_len += strlen(query_author);
359 if (flag & PMINFO_PKGINFO_GET_LABEL) {
360 strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
361 query_len += strlen(query_label);
362 bind_params = g_list_append(bind_params, strdup(locale));
364 if (flag & PMINFO_PKGINFO_GET_ICON) {
365 strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
366 query_len += strlen(query_icon);
367 bind_params = g_list_append(bind_params, strdup(locale));
369 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
370 strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
371 query_len += strlen(query_description);
372 bind_params = g_list_append(bind_params, strdup(locale));
375 strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
376 query_len += strlen(query_from_clause);
378 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
379 if (ret != PMINFO_R_OK) {
380 LOGE("Failed to get WHERE clause");
385 strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
387 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
388 if (ret != SQLITE_OK) {
389 LOGE("prepare failed: %s", sqlite3_errmsg(db));
390 ret = PMINFO_R_ERROR;
394 ret = __bind_params(stmt, bind_params);
395 if (ret != SQLITE_OK) {
396 LOGE("Failed to bind parameters");
400 while (sqlite3_step(stmt) == SQLITE_ROW) {
401 info = calloc(1, sizeof(package_x));
403 LOGE("out of memory");
404 sqlite3_finalize(stmt);
405 sqlite3_close_v2(db);
406 return PMINFO_R_ERROR;
409 _save_column_str(stmt, idx++, &info->package);
410 if (g_hash_table_contains(packages,
411 (gconstpointer)info->package)) {
416 _save_column_str(stmt, idx++, &info->version);
417 _save_column_str(stmt, idx++, &info->installlocation);
418 _save_column_str(stmt, idx++, &info->removable);
419 _save_column_str(stmt, idx++, &info->preload);
420 _save_column_str(stmt, idx++, &info->readonly);
421 _save_column_str(stmt, idx++, &info->update);
422 _save_column_str(stmt, idx++, &info->appsetting);
423 _save_column_str(stmt, idx++, &info->system);
424 _save_column_str(stmt, idx++, &info->type);
425 _save_column_str(stmt, idx++, &info->package_size);
426 _save_column_str(stmt, idx++, &info->installed_time);
427 _save_column_str(stmt, idx++, &info->installed_storage);
428 _save_column_str(stmt, idx++, &info->storeclient_id);
429 _save_column_str(stmt, idx++, &info->mainapp_id);
430 _save_column_str(stmt, idx++, &info->package_url);
431 _save_column_str(stmt, idx++, &info->root_path);
432 _save_column_str(stmt, idx++, &info->csc_path);
433 _save_column_str(stmt, idx++, &info->nodisplay_setting);
434 _save_column_str(stmt, idx++, &info->api_version);
435 _save_column_str(stmt, idx++, &info->support_disable);
436 _save_column_str(stmt, idx++, &info->tep_name);
437 _save_column_str(stmt, idx++, &info->zip_mount_file);
438 _save_column_str(stmt, idx++, &info->external_path);
439 _save_column_str(stmt, idx++, &info->support_mode);
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 if (__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
504 ret = PMINFO_R_ERROR;
505 pkgmgrinfo_basic_free_package(info);
510 g_hash_table_insert(packages, (gpointer)info->package,
520 if (ret != PMINFO_R_OK && info != NULL)
521 pkgmgrinfo_basic_free_package(info);
524 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
526 g_list_free_full(bind_params, free);
527 sqlite3_close_v2(db);
528 sqlite3_finalize(stmt);
533 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
534 pkgmgrinfo_filter_x *filter, int flag,
535 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
540 pkgmgr_pkginfo_x info;
545 locale = _get_system_locale();
547 return PMINFO_R_ERROR;
549 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
553 return PMINFO_R_ERROR;
556 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
557 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
558 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
561 if (ret != PMINFO_R_OK) {
562 g_hash_table_destroy(list);
564 return PMINFO_R_ERROR;
567 g_hash_table_iter_init(&iter, list);
568 while (g_hash_table_iter_next(&iter, NULL, &value)) {
569 pkg = (package_x *)value;
572 info.locale = locale;
573 if (pkg_list_cb(&info, user_data) < 0)
577 g_hash_table_destroy(list);
583 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
584 pkgmgrinfo_pkginfo_h *handle)
589 pkgmgrinfo_pkginfo_filter_h filter;
590 pkgmgr_pkginfo_x *info;
592 if (pkgid == NULL || handle == NULL) {
593 LOGE("invalid parameter");
594 return PMINFO_R_EINVAL;
597 locale = _get_system_locale();
599 return PMINFO_R_ERROR;
601 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
602 if (ret != PMINFO_R_OK) {
607 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
608 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
609 if (ret != PMINFO_R_OK) {
610 pkgmgrinfo_pkginfo_filter_destroy(filter);
612 return PMINFO_R_ERROR;
615 list = g_hash_table_new(g_str_hash, g_str_equal);
617 pkgmgrinfo_pkginfo_filter_destroy(filter);
619 return PMINFO_R_ERROR;
622 ret = _pkginfo_get_packages(uid, locale, filter,
623 PMINFO_PKGINFO_GET_ALL, list);
624 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
625 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
626 PMINFO_PKGINFO_GET_ALL, list);
628 pkgmgrinfo_pkginfo_filter_destroy(filter);
629 if (ret != PMINFO_R_OK) {
630 g_hash_table_destroy(list);
635 if (!g_hash_table_size(list)) {
636 _LOGI("pkginfo for [%s] is not existed for user [%d]",
638 g_hash_table_destroy(list);
640 return PMINFO_R_ENOENT;
643 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
645 _LOGE("out of memory");
646 g_hash_table_destroy(list);
648 return PMINFO_R_ERROR;
652 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
653 info->locale = locale;
655 /* just free list only */
656 g_hash_table_destroy(list);
663 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
664 pkgmgrinfo_pkginfo_h *handle)
666 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
669 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
670 int flag, void *user_data, uid_t uid)
672 if (pkg_list_cb == NULL) {
673 LOGE("invalid parameter");
674 return PMINFO_R_EINVAL;
677 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
678 pkg_list_cb, user_data);
681 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
682 int flag, void *user_data)
684 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
685 user_data, _getuid());
688 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
689 void *user_data, uid_t uid)
691 if (pkg_list_cb == NULL) {
692 LOGE("invalid parameter");
693 return PMINFO_R_EINVAL;
696 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
697 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
700 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
703 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
707 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
709 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
711 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
712 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
714 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
715 return PMINFO_R_ERROR;
717 *pkg_name = (char *)info->pkg_info->package;
722 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
724 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
726 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
727 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
729 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
730 return PMINFO_R_ERROR;
732 *pkgid = (char *)info->pkg_info->package;
737 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
739 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
741 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
742 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
744 if (info->pkg_info == NULL)
745 return PMINFO_R_ERROR;
747 if (info->pkg_info->type == NULL)
750 *type = (char *)info->pkg_info->type;
755 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
757 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
759 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
760 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
762 if (info->pkg_info == NULL)
763 return PMINFO_R_ERROR;
765 if (info->pkg_info->version == NULL)
768 *version = (char *)info->pkg_info->version;
773 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
775 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
777 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
778 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
780 if (info->pkg_info == NULL)
781 return PMINFO_R_ERROR;
783 if (info->pkg_info->api_version == NULL)
786 *api_version = (char *)info->pkg_info->api_version;
791 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
793 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
795 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
796 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
798 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
799 return PMINFO_R_ERROR;
801 *tep_name = (char *)info->pkg_info->tep_name;
806 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
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(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
813 if (info->pkg_info == NULL)
814 return PMINFO_R_ERROR;
816 if (info->pkg_info->zip_mount_file == NULL)
817 *zip_mount_file = "";
819 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
824 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
827 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
829 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
830 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
832 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
833 return PMINFO_R_ERROR;
835 val = (char *)info->pkg_info->installlocation;
836 if (strcmp(val, "internal-only") == 0)
837 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
838 else if (strcmp(val, "prefer-external") == 0)
839 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
841 *location = PMINFO_INSTALL_LOCATION_AUTO;
846 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
848 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
852 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
854 if (info->pkg_info == NULL)
855 return PMINFO_R_ERROR;
857 if (info->pkg_info->package_size == NULL) {
860 _LOGE("out of memory");
861 return PMINFO_R_ERROR;
863 info->pkg_info->package_size = temp;
867 *size = atoi((char *)info->pkg_info->package_size);
872 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
875 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
877 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
878 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
880 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
881 return PMINFO_R_ERROR;
883 ptr = (icon_x *)info->pkg_info->icon->data;
885 return PMINFO_R_ERROR;
887 /* TODO : should we return empty string if there was no icon? */
888 if (ptr->text == NULL)
896 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
899 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
901 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
902 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
904 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
905 return PMINFO_R_ERROR;
907 ptr = (label_x *)info->pkg_info->label->data;
909 return PMINFO_R_ERROR;
911 /* TODO : should we return empty string if there was no label? */
912 if (ptr->text == NULL)
920 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
923 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
926 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
928 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
929 return PMINFO_R_ERROR;
931 ptr = (description_x *)info->pkg_info->description->data;
933 return PMINFO_R_ERROR;
935 if (ptr->text == NULL)
938 *description = (char *)ptr->text;
943 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
945 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
948 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
949 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
951 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
952 return PMINFO_R_ERROR;
954 author = (author_x *)info->pkg_info->author->data;
956 return PMINFO_R_ERROR;
958 if (author->text == NULL)
961 *author_name = (char *)author->text;
966 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
968 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
971 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
972 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
974 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
975 return PMINFO_R_ERROR;
977 author = (author_x *)info->pkg_info->author->data;
979 return PMINFO_R_ERROR;
981 if (author->email == NULL)
984 *author_email = (char *)author->email;
989 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
991 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
994 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
995 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
997 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
998 return PMINFO_R_ERROR;
1000 author = (author_x *)info->pkg_info->author->data;
1002 return PMINFO_R_ERROR;
1004 if (author->href == NULL)
1007 *author_href = (char *)author->href;
1012 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1014 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1016 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1017 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1019 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1020 return PMINFO_R_ERROR;
1022 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1023 *storage = PMINFO_INTERNAL_STORAGE;
1024 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1025 *storage = PMINFO_EXTERNAL_STORAGE;
1027 return PMINFO_R_ERROR;
1032 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1034 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1037 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1039 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1040 return PMINFO_R_ERROR;
1042 *installed_time = atoi(info->pkg_info->installed_time);
1047 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1049 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1051 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1052 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1054 if (info->pkg_info == NULL)
1055 return PMINFO_R_ERROR;
1057 if (info->pkg_info->storeclient_id == NULL)
1058 *storeclientid = "";
1060 *storeclientid = (char *)info->pkg_info->storeclient_id;
1065 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1067 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1070 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1072 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1073 return PMINFO_R_ERROR;
1075 *mainappid = (char *)info->pkg_info->mainapp_id;
1080 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1082 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1084 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1085 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1087 if (info->pkg_info == NULL)
1088 return PMINFO_R_ERROR;
1090 if (info->pkg_info->package_url == NULL)
1093 *url = (char *)info->pkg_info->package_url;
1098 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1100 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1102 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1103 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1105 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1106 return PMINFO_R_ERROR;
1108 *path = (char *)info->pkg_info->root_path;
1113 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1115 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1117 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1118 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1120 if (info->pkg_info == NULL)
1121 return PMINFO_R_ERROR;
1123 if (info->pkg_info->csc_path == NULL)
1126 *path = (char *)info->pkg_info->csc_path;
1131 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1133 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1134 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1136 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1137 if (info->pkg_info->support_mode)
1138 *support_mode = atoi(info->pkg_info->support_mode);
1145 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1148 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1150 #if 0 /* smack issue occured, check later */
1152 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1153 if (pkgid == NULL) {
1154 _LOGD("invalid func parameters\n");
1155 return PMINFO_R_ERROR;
1157 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1160 char app_mmc_path[FILENAME_MAX] = { 0, };
1161 char app_dir_path[FILENAME_MAX] = { 0, };
1162 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1163 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1164 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1165 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1167 /*check whether application is in external memory or not */
1168 fp = fopen(app_mmc_path, "r");
1170 _LOGD(" app path in external memory not accesible\n");
1175 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1179 /*check whether application is in internal or not */
1181 _LOGD(" app path in internal memory not accesible\n");
1183 return PMINFO_R_ERROR;
1186 /*check whether the application is installed in SD card
1187 but SD card is not present*/
1188 fp = fopen(app_mmc_internal_path, "r");
1191 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1195 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1200 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1207 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1209 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1211 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1212 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1214 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1215 return PMINFO_R_ERROR;
1217 *removable = _get_bool_value(info->pkg_info->removable);
1222 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1227 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1228 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1230 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1231 return PMINFO_R_ERROR;
1233 val = (char *)info->pkg_info->installlocation;
1234 if (strcmp(val, "internal-only") == 0)
1236 else if (strcmp(val, "prefer-external") == 0)
1244 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1246 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1248 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1249 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1251 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1252 return PMINFO_R_ERROR;
1254 *preload = _get_bool_value(info->pkg_info->preload);
1259 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1261 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1263 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1264 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1266 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1267 return PMINFO_R_ERROR;
1269 *system = _get_bool_value(info->pkg_info->system);
1274 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1276 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1279 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1281 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1282 return PMINFO_R_ERROR;
1284 *readonly = _get_bool_value(info->pkg_info->readonly);
1289 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1291 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1293 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1294 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1296 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1297 return PMINFO_R_ERROR;
1299 *update = _get_bool_value(info->pkg_info->update);
1304 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1306 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1308 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1309 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1311 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1312 return PMINFO_R_ERROR;
1314 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1319 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1321 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1324 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1326 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1327 return PMINFO_R_ERROR;
1329 *global = _get_bool_value(info->pkg_info->for_all_users);
1334 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1336 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1339 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1341 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1343 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1345 __cleanup_pkginfo(info);
1350 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1352 pkgmgrinfo_filter_x *filter;
1354 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1356 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1357 if (filter == NULL) {
1358 _LOGE("Out of Memory!!!");
1359 return PMINFO_R_ERROR;
1367 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1369 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1374 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1375 g_slist_free(filter->list);
1383 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1384 const char *property, const int value)
1386 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1390 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1391 pkgmgrinfo_node_x *node;
1393 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1394 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1396 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1397 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1398 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1399 _LOGE("Invalid Integer Property\n");
1400 return PMINFO_R_EINVAL;
1402 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1404 _LOGE("Out of Memory!!!\n");
1405 return PMINFO_R_ERROR;
1407 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1408 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1410 _LOGE("Out of Memory\n");
1412 return PMINFO_R_ERROR;
1416 /*If API is called multiple times for same property, we should override the previous values.
1417 Last value set will be used for filtering.*/
1418 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1420 filter->list = g_slist_delete_link(filter->list, link);
1421 filter->list = g_slist_append(filter->list, (gpointer)node);
1426 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1427 const char *property, const bool value)
1432 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1433 pkgmgrinfo_node_x *node;
1435 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1436 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1438 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1439 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1440 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1441 _LOGE("Invalid Boolean Property\n");
1442 return PMINFO_R_EINVAL;
1444 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1446 _LOGE("Out of Memory!!!\n");
1447 return PMINFO_R_ERROR;
1450 val = strndup("true", 4);
1452 val = strndup("false", 5);
1454 _LOGE("Out of Memory\n");
1456 return PMINFO_R_ERROR;
1460 /*If API is called multiple times for same property, we should override the previous values.
1461 Last value set will be used for filtering.*/
1462 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1464 filter->list = g_slist_delete_link(filter->list, link);
1465 filter->list = g_slist_append(filter->list, (gpointer)node);
1470 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1471 const char *property, const char *value)
1476 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1477 pkgmgrinfo_node_x *node;
1479 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1480 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1481 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1483 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1484 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1485 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1486 _LOGE("Invalid String Property\n");
1487 return PMINFO_R_EINVAL;
1489 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1491 _LOGE("Out of Memory!!!\n");
1492 return PMINFO_R_ERROR;
1494 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1495 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1496 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1497 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1498 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1499 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1500 else if (strcmp(value, "installed_internal") == 0)
1501 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1502 else if (strcmp(value, "installed_external") == 0)
1503 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1505 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1507 _LOGE("Out of Memory\n");
1509 return PMINFO_R_ERROR;
1513 /*If API is called multiple times for same property, we should override the previous values.
1514 Last value set will be used for filtering.*/
1515 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1517 filter->list = g_slist_delete_link(filter->list, link);
1518 filter->list = g_slist_append(filter->list, (gpointer)node);
1523 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1527 GHashTable *list = NULL;
1529 if (handle == NULL || count == NULL) {
1530 _LOGE("invalid parameter");
1531 return PMINFO_R_EINVAL;
1534 locale = _get_system_locale();
1536 return PMINFO_R_ERROR;
1538 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1542 return PMINFO_R_ERROR;
1545 ret = _pkginfo_get_packages(uid, locale,
1546 (pkgmgrinfo_filter_x *)handle, 0, list);
1547 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1548 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1551 if (ret != PMINFO_R_OK) {
1552 g_hash_table_destroy(list);
1554 return PMINFO_R_ERROR;
1557 *count = g_hash_table_size(list);
1559 g_hash_table_destroy(list);
1565 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1567 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1570 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1571 pkgmgrinfo_pkginfo_filter_h handle,
1572 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1574 if (handle == NULL || pkg_cb == NULL) {
1575 LOGE("invalid parameter");
1576 return PMINFO_R_EINVAL;
1579 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1580 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1583 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1584 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1586 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1589 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1590 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1593 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1595 privilege_x *privilege;
1597 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1599 if (info->pkg_info == NULL)
1600 return PMINFO_R_ERROR;
1602 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1603 privilege = (privilege_x *)tmp->data;
1604 if (privilege == NULL)
1606 ret = privilege_func(privilege->value, user_data);