Pass empty filter when the input filter is null 57/105757/3 accepted/tizen/3.0/common/20161227.101228 accepted/tizen/3.0/ivi/20161222.024817 accepted/tizen/3.0/mobile/20161222.024650 accepted/tizen/3.0/tv/20161222.024726 accepted/tizen/3.0/wearable/20161222.024747 submit/tizen_3.0/20161221.130430
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 19 Dec 2016 10:31:22 +0000 (19:31 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 19 Dec 2016 11:03:02 +0000 (20:03 +0900)
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 <s89.jang@samsung.com>
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_pkginfo.c

index fe57406..4feacd5 100644 (file)
@@ -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,
index 8ecb9ab..5add4b0 100644 (file)
@@ -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,