From: Ilho Kim Date: Fri, 2 Jul 2021 09:13:54 +0000 (+0900) Subject: Add api for resource package X-Git-Tag: accepted/tizen/unified/20210818.124656~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=114054c00e798b859d9610aa89dd4c226d3731e5;hp=05bc8fa5ebb9da6de4a2169b28df2110515fae0a;p=platform%2Fcore%2Fapi%2Fpackage-manager.git Add api for resource package Change-Id: I9ca085f164c1652a895bf3cfea0c048a1b03e504 Signed-off-by: Ilho Kim --- diff --git a/include/package_info.h b/include/package_info.h index 5e9ce5b..9305e02 100644 --- a/include/package_info.h +++ b/include/package_info.h @@ -47,6 +47,13 @@ typedef struct package_info_s *package_info_h; typedef struct package_updateinfo_s *package_updateinfo_h; /** + * @brief The required privilege handle. + * @since_tizen 6.5 + * @see package_info_foreach_required_privilege() + */ +typedef struct allowed_package_required_privilege_s *allowed_package_required_privilege_h; + +/** * @brief Enumeration for storage type. * @since_tizen 2.3 */ @@ -184,6 +191,21 @@ typedef bool (*package_info_dependency_info_cb) (const char *from, const char *t /** + * @brief Called to get the allowed package information of resource package. + * @since_tizen 6.5 + * @remarks @a allowed_package, @a privilege_handle are managed by the platform and will be released after the callback exits. + * @param[in] allowed_package The ID of allowed package + * @param[in] privilege_handle The privilege handle required by resource package + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * otherwise @c false to break out of the loop + * @pre package_info_foreach_res_allowed_package() will invoke this callback. + * @see package_info_foreach_res_allowed_package() + */ +typedef bool (*package_info_res_allowed_package_cb) (const char *allowed_package, allowed_package_required_privilege_h privilege_handle, void *user_data); + + +/** * @brief Retrieves all application IDs of each package. * @since_tizen 2.3 * @param[in] package_info The package info handle @@ -360,6 +382,38 @@ int package_info_get_tep_name(package_info_h package_info, char **name); /** + * @brief Gets the resource type of the package. + * @since_tizen 6.5 + * @remarks You must release @a res_type using free(). + * @param[in] package_info The package information + * @param[out] res_type The resource type of the package + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR I/O error + */ +int package_info_get_res_type(package_info_h package_info, char **res_type); + + +/** + * @brief Gets the resource version of the package. + * @since_tizen 6.5 + * @remarks You must release @a res_version using free(). + * @param[in] package_info The package information + * @param[out] res_version The resource version of the package + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR I/O error + */ +int package_info_get_res_version(package_info_h package_info, char **res_version); + + +/** * @brief Checks whether the package is system package. * @since_tizen 2.3 * @param[in] package_info The package information @@ -560,6 +614,40 @@ int package_info_foreach_dependency_info(package_info_h package_info, package_in */ int package_info_foreach_dependency_info_depends_on(package_info_h package_info, package_info_dependency_info_cb callback, void *user_data); + +/** + * @brief Retrieves allowed package information of the resource package. + * @details Resource packages allow access to allowed data only for allowed packages that have specific privileges. + * If not, they just allow access to global data + * @since_tizen 6.5 + * @param[in] package_info The package information + * @param[in] callback The iteration callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR I/O error + * @retval #PACKAGE_MANAGER_ERROR_SYSTEM_ERROR Severe system error + */ +int package_info_foreach_res_allowed_package(package_info_h package_info, package_info_res_allowed_package_cb callback, void *user_data); + + +/** + * @brief Retrieves required privilege information of the allowed package. + * @details The packages want to access in the allowed area of resource package must have all the privileges required by resource package. + * @since_tizen 6.5 + * @param[in] priv_info The privilege information handle + * @param[in] callback The iteration callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + */ +int package_info_foreach_required_privilege(allowed_package_required_privilege_h priv_info, package_info_privilege_info_cb callback, void *user_data); + + /** * @brief Gets the package update information for the given package. * @since_tizen 4.0 diff --git a/include/package_manager.h b/include/package_manager.h index 8a55af2..bcb0b21 100644 --- a/include/package_manager.h +++ b/include/package_manager.h @@ -72,6 +72,13 @@ extern "C" { /** + * @brief Definition for value to be used when filtering based on resource type: String property for filtering packages with specific resource types. + * @since_tizen 6.5 + */ +#define PACKAGE_MANAGER_PKGINFO_RES_TYPE "PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE" + + +/** * @brief Enumeration for error code. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ @@ -603,6 +610,25 @@ int package_manager_filter_add_bool(package_manager_filter_h handle, const char /** + * @brief Adds a string filter property to the filter handle. + * @since_tizen 6.5 + * @param[in] handle pointer to the package info filter handle + * @param[in] property string property name + * @param[in] value value corresponding to the property + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR I/O error + * @pre package_manager_filter_create() + * @post package_manager_filter_destroy() + * @see package_manager_filter_count() + * @see package_manager_filter_foreach_package_info() + */ +int package_manager_filter_add_string(package_manager_filter_h handle, const char *property, const char *value); + + +/** * @brief Counts the package that satisfy the filter conditions. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public diff --git a/src/package_info.c b/src/package_info.c index 5ea5e0c..8e8c713 100644 --- a/src/package_info.c +++ b/src/package_info.c @@ -42,6 +42,10 @@ typedef struct package_updateinfo_s { pkgmgrinfo_updateinfo_h update_info; } package_updateinfo_s; +typedef struct allowed_package_required_privilege_s { + required_privilege_h priv; +} allowed_package_required_privilege_s; + typedef struct _foreach_app_context_ { package_info_app_cb callback; void *user_data; @@ -62,6 +66,11 @@ typedef struct _foreach_dependency_ { void *user_data; } foreach_dependency_s; +typedef struct _foreach_res_allowed_package_ { + package_info_res_allowed_package_cb callback; + void *user_data; +} foreach_res_allowed_package_s; + static int package_info_foreach_updateinfo_cb(const pkgmgrinfo_updateinfo_h handle, void *user_data) { foreach_updateinfo_context_s *foreach_updateinfo = user_data; @@ -399,6 +408,50 @@ API int package_info_get_tep_name(package_info_h package_info, char **name) return PACKAGE_MANAGER_ERROR_NONE; } +API int package_info_get_res_type(package_info_h package_info, char **res_type) +{ + char *pkg_info_value = NULL; + char *res_type_dup = NULL; + + if (package_info == NULL || res_type == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + if (pkgmgrinfo_pkginfo_get_res_type(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK) + return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + res_type_dup = strdup(pkg_info_value); + + if (res_type_dup == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + +END: + *res_type = res_type_dup; + + return PACKAGE_MANAGER_ERROR_NONE; +} + +API int package_info_get_res_version(package_info_h package_info, char **res_version) +{ + char *pkg_info_value = NULL; + char *res_version_dup = NULL; + + if (package_info == NULL || res_version == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + if (pkgmgrinfo_pkginfo_get_res_version(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK) + return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + res_version_dup = strdup(pkg_info_value); + + if (res_version_dup == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + +END: + *res_version = res_version_dup; + + return PACKAGE_MANAGER_ERROR_NONE; +} + API int package_info_is_system_package(package_info_h package_info, bool *system) { bool pkg_info_value = false; @@ -624,6 +677,57 @@ API int package_info_foreach_dependency_info_depends_on(package_info_h package_i return PACKAGE_MANAGER_ERROR_NONE; } +static int package_info_foreach_res_allowed_package_cb(const char *allowed_package, required_privilege_h privilege_handle, void *user_data) +{ + foreach_res_allowed_package_s *foreach_res_allowed_package = (foreach_res_allowed_package_s *)user_data; + allowed_package_required_privilege_s allowed_package_required_privilege = { + .priv = privilege_handle, + }; + + if (!foreach_res_allowed_package->callback(allowed_package, &allowed_package_required_privilege, foreach_res_allowed_package->user_data)) + return -1; + else + return 0; +} + +API int package_info_foreach_res_allowed_package(package_info_h package_info, package_info_res_allowed_package_cb callback, void *user_data) +{ + int ret = 0; + foreach_res_allowed_package_s foreach_res_allowed_package = { + .callback = callback, + .user_data = user_data, + }; + + if (package_info == NULL || callback == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + ret = pkgmgrinfo_pkginfo_foreach_res_allowed_package(package_info->pkgmgr_pkginfo, package_info_foreach_res_allowed_package_cb, &foreach_res_allowed_package); + if (ret == PMINFO_R_EINVAL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + else if (ret == PMINFO_R_ERROR) + return package_manager_error(PACKAGE_MANAGER_ERROR_SYSTEM_ERROR, __FUNCTION__, NULL); + + return PACKAGE_MANAGER_ERROR_NONE; +} + +API int package_info_foreach_required_privilege(allowed_package_required_privilege_h priv_info, package_info_privilege_info_cb callback, void *user_data) +{ + int ret = 0; + foreach_privilege_s foreach_privilege = { + .callback = callback, + .user_data = user_data, + }; + + if (priv_info == NULL || callback == NULL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + ret = pkgmgrinfo_pkginfo_foreach_required_privilege(priv_info->priv, package_info_foreach_privilege_cb, &foreach_privilege); + if (ret == PMINFO_R_EINVAL) + return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + return PACKAGE_MANAGER_ERROR_NONE; +} + API int package_info_updateinfo_create(const char *pkgid, package_updateinfo_h *info) { int ret; diff --git a/src/package_manager.c b/src/package_manager.c index d9611a6..2485c5f 100644 --- a/src/package_manager.c +++ b/src/package_manager.c @@ -1917,6 +1917,25 @@ API int package_manager_filter_add_bool(package_manager_filter_h handle, return PACKAGE_MANAGER_ERROR_NONE; } + +API int package_manager_filter_add_string(package_manager_filter_h handle, const char *property, const char *value) +{ + int retval; + + if ((handle == NULL) || (property == NULL) || (value == NULL)) { + return + package_manager_error + (PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, + NULL); + } + + retval = pkgmgrinfo_pkginfo_filter_add_string(handle, property, value); + if (retval != PACKAGE_MANAGER_ERROR_NONE) + return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + return PACKAGE_MANAGER_ERROR_NONE; +} + API int package_manager_filter_count(package_manager_filter_h handle, int *count) { int retval;