From 757e786f265e493aeb82cd39f53f530067ead43e Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 19 Dec 2016 19:31:22 +0900 Subject: [PATCH] Pass empty filter when the input filter is null Now filtered_foreach functions do something with input filter, so the filter should not be null. For making more simple and imporving readabilty, create and pass filter before calling filtered_foreach. Change-Id: I4cc3d138900d671f80521de70faf3fab835d5d73 Signed-off-by: Sangyoon Jang --- src/pkgmgrinfo_appinfo.c | 38 +++++++++++++++++--------------------- src/pkgmgrinfo_pkginfo.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index fe57406..4feacd5 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -1284,7 +1284,6 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, char *locale; application_x *app; pkgmgr_appinfo_x info; - pkgmgrinfo_filter_x *tmp_filter = NULL; GHashTable *list; GHashTableIter iter; gpointer value; @@ -1300,30 +1299,18 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, return PMINFO_R_ERROR; } - if (filter != NULL) { - tmp_filter = filter; - } else { - ret = pkgmgrinfo_appinfo_filter_create((void *)&tmp_filter); - if (ret != PMINFO_R_OK) { - _LOGE("Failed to create filter"); - return PMINFO_R_ERROR; - } - } - - if (__check_disable_filter_exist(tmp_filter) == false) - pkgmgrinfo_appinfo_filter_add_bool(tmp_filter, + if (__check_disable_filter_exist(filter) == false) + pkgmgrinfo_appinfo_filter_add_bool(filter, PMINFO_APPINFO_PROP_APP_DISABLE, false); - ret = _appinfo_get_applications(uid, uid, locale, tmp_filter, flag, list); + ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list); if (ret == PMINFO_R_OK && uid != GLOBAL_USER) ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, - tmp_filter, flag, list); + filter, flag, list); if (ret != PMINFO_R_OK) { g_hash_table_destroy(list); free(locale); - if (filter == NULL) - pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); return ret; } @@ -1339,9 +1326,6 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, g_hash_table_destroy(list); free(locale); - if (filter == NULL) - pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); - return PMINFO_R_OK; } @@ -1472,13 +1456,25 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, API int pkgmgrinfo_appinfo_get_usr_installed_list( pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data) { + int ret; + pkgmgrinfo_appinfo_filter_h filter; + if (app_func == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _appinfo_get_filtered_foreach_appinfo(uid, NULL, + /* create an empty filter */ + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, PMINFO_APPINFO_GET_ALL, app_func, user_data); + + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index 8ecb9ab..5add4b0 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -883,13 +883,25 @@ API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid, API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, int flag, void *user_data, uid_t uid) { + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + if (pkg_list_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag, + /* create an empty filter */ + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag, pkg_list_cb, user_data); + + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, @@ -902,13 +914,25 @@ API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid) { + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + if (pkg_list_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, + /* create an empty filter */ + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data); + + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, -- 2.7.4