From: Junghyun Yeon Date: Tue, 22 Nov 2016 08:44:41 +0000 (+0900) Subject: Add new functions to retrieve information of disabled package X-Git-Tag: accepted/tizen/3.0/common/20161125.101758^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F99263%2F3;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Add new functions to retrieve information of disabled package - add function pkgmgrinfo_pkginfo_get_usr_all_pkginfo function to retrieve information of disabled packages Change-Id: Ie4d20981ea84dcc82e61638b464689511e9e703e Signed-off-by: Junghyun Yeon Signed-off-by: jongmyeongko --- diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index d561284..bab6ffd 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -247,7 +247,7 @@ int pkgmgrinfo_pkginfo_get_usr_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, /** * @fn int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle) - * @brief This API creates the package information handle from db + * @brief This API creates the package information handle from db which is not disabled * * @par This API is for package-manager client application * @par Sync (or) Async : Synchronous API @@ -308,6 +308,47 @@ int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid, pkgmgrinfo_pkginf int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle); /** + * @fn int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle) + * @brief This API creates the package information handle from db regardless of its disable status + * + * @par This API is for package-manager client application + * @par Sync (or) Async : Synchronous API + * + * @param[in] pkgid pointer to package ID + * @param[in] uid the addressee user id of the instruction + * @param[out] handle pointer to the package info handle. + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @retval PMINFO_R_ERROR internal error + * @pre None + * @post pkgmgrinfo_pkginfo_destroy_pkginfo() + * @see pkgmgrinfo_pkginfo_get_pkgid() + * @see pkgmgrinfo_pkginfo_is_removable() + * @code +static int get_pkg_type(const char *pkgid) +{ + int ret = 0; + char *type = NULL; + pkgmgrinfo_pkginfo_h handle; + ret = pkgmgrinfo_pkginfo_get_all_pkginfo(pkgid, &handle); + if (ret != PMINFO_R_OK) + return -1; + ret = pkgmgrinfo_pkginfo_get_type(handle, &type); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return -1; + } + printf("pkgtype: %s\n", type); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return 0; +} + * @endcode + */ +int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle); +int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle); + +/** * @fn int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name) * @brief This API gets the package name from the package ID * diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index a593e0a..3a2c3a6 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -371,12 +371,6 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, } } - /* add package_disable='false' clause by default */ - if (__check_disable_filter_exist(tmp_filter) == false) - pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, - PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); - - query_len = strlen(query_raw); snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); if (flag & PMINFO_PKGINFO_GET_AUTHOR) { @@ -565,6 +559,7 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, char *locale; package_x *pkg; pkgmgr_pkginfo_x info; + pkgmgrinfo_filter_x *tmp_filter = NULL; GHashTable *list; GHashTableIter iter; gpointer value; @@ -580,6 +575,20 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, return PMINFO_R_ERROR; } + if (filter != NULL) { + tmp_filter = (pkgmgrinfo_filter_x *)filter; + } else { + ret = pkgmgrinfo_pkginfo_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_pkginfo_filter_add_bool(tmp_filter, + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); + ret = _pkginfo_get_packages(uid, locale, filter, flag, list); if (ret == PMINFO_R_OK && uid != GLOBAL_USER) ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, @@ -588,6 +597,8 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, if (ret != PMINFO_R_OK) { g_hash_table_destroy(list); free(locale); + if (filter == NULL) + pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); return PMINFO_R_ERROR; } @@ -604,41 +615,29 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, g_hash_table_destroy(list); free(locale); + if (filter == NULL) + pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); + return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, - pkgmgrinfo_pkginfo_h *handle) +static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, + pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle) { int ret; char *locale; GHashTable *list; - pkgmgrinfo_pkginfo_filter_h filter; pkgmgr_pkginfo_x *info; - if (pkgid == NULL || handle == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; + if (pkgid == NULL || filter == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } locale = _get_system_locale(); if (locale == NULL) return PMINFO_R_ERROR; - ret = pkgmgrinfo_pkginfo_filter_create(&filter); - if (ret != PMINFO_R_OK) { - free(locale); - return ret; - } - - ret = pkgmgrinfo_pkginfo_filter_add_string(filter, - PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_pkginfo_filter_destroy(filter); - free(locale); - return PMINFO_R_ERROR; - } - list = g_hash_table_new(g_str_hash, g_str_equal); if (list == NULL) { pkgmgrinfo_pkginfo_filter_destroy(filter); @@ -652,13 +651,6 @@ API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, PMINFO_PKGINFO_GET_ALL, list); - pkgmgrinfo_pkginfo_filter_destroy(filter); - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(locale); - return ret; - } - if (!g_hash_table_size(list)) { _LOGI("pkginfo for [%s] is not existed for user [%d]", pkgid, uid); @@ -685,6 +677,43 @@ API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, *handle = info; return ret; + + +} + +API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, + pkgmgrinfo_pkginfo_h *handle) +{ + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + + if (pkgid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_pkginfo_filter_add_string(filter, + PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = pkgmgrinfo_pkginfo_filter_add_bool(filter, + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle); + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, @@ -781,6 +810,35 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, return ret; } +API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid, + pkgmgrinfo_pkginfo_h *handle) +{ + + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + + if (pkgid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_pkginfo_filter_add_string(filter, + PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle); + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; +} + API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle) { @@ -788,6 +846,12 @@ API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid, handle); } +API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid, + pkgmgrinfo_pkginfo_h *handle) +{ + return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle); +} + API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, int flag, void *user_data, uid_t uid) { @@ -1701,6 +1765,15 @@ API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, return PMINFO_R_ERROR; } + if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) { + ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); + if (ret != PMINFO_R_OK) { + free(locale); + return PMINFO_R_ERROR; + } + } + ret = _pkginfo_get_packages(uid, locale, (pkgmgrinfo_filter_x *)handle, 0, list); if (ret == PMINFO_R_OK && uid != GLOBAL_USER)