From: Ilho Kim Date: Mon, 5 Jul 2021 08:34:43 +0000 (+0900) Subject: Add api for resource package X-Git-Tag: submit/tizen/20210811.070347~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02d80c0da510c34e39e12c8a251bc47b66322b38;p=platform%2Fcore%2Fapi%2Fapp-manager.git Add api for resource package Change-Id: I95a619776dfe160ceabc869f2a5f2337653fa454 Signed-off-by: Ilho Kim --- diff --git a/include/app_info.h b/include/app_info.h index 6ed44da..70b4bba 100644 --- a/include/app_info.h +++ b/include/app_info.h @@ -161,6 +161,24 @@ typedef bool (*app_info_metadata_cb) (const char *metadata_key, const char *meta */ typedef bool (*app_info_category_cb) (const char *category, void *user_data); +/** + * @brief Called for each application resource control in app_info_foreach_res_control(). + * @since_tizen 6.5 + * @remarks @a res_type, @a min_res_version, @a max_res_version, and @a auto_close are managed by the platform and will be released after the callback exits. + * @param[in] res_type The resource type + * @param[in] min_res_version The minimum version of the resource package to use + * @param[in] max_res_version The maximum version of the resource package to use + * @param[in] auto_close The value of auto close + * @param[in] user_data The user data passed to app_info_foreach_res_control() + * @return @c true to continue with the next iteration of the loop, \n + * otherwise @c false to break out of the loop + * @pre app_info_foreach_res_control() will invoke this callback. + * @see app_info_foreach_res_control() + */ +typedef bool (*app_info_res_control_cb) (const char *res_type, + const char *min_res_version, const char *max_res_version, + const char *auto_close, void *user_data); + /** * @brief Creates the application information handle. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -573,6 +591,69 @@ int app_info_metadata_filter_add(app_info_metadata_filter_h handle, const char * */ int app_info_metadata_filter_foreach(app_info_metadata_filter_h handle, app_info_filter_cb callback, void *user_data); +/** + * @brief Gets the list of resource controls for a particular application. + * @details If a application has declared @b res_control and there is an available resource allowed by the resource package, the application uses the allowed resource of highest @b res_version of resource package among them. + * If a application has declared @b res_control and there is an available resource package, the application uses the global resource of highest @b res_version of resource package among them. + * The allowed resource can be accessed at @b {rootpath}/mount/allowed/{res_type} and the global resource can be accessed at @b {rootpath}/mount/global/{res_type} + * If the application declared @b res_control with @b auto_close 'true' and the resource package which the application is using is updated, the application will be terminated. + * + * If an application 'appA' declared @b res_control like below * + * + * + * + * + * + * + * + * + * + * + * + *
res_type min_res_version max_res_version
ai_model 1.0.0 2.0.0
+ * and there are resource packages with res_type 'ai_model' like below + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
package res_type res_version allowes 'appA'?
ai_1 ai_model 0.0.1 yes
ai_2 ai_model 1.0.0 yes
ai_3 ai_model 2.0.0 no
+ * 'ai_1' package's @b res_version is lower than 'appA's @b min_res_version in @b res_control so 'ai_1' is not available. + * 'ai_2' is available and allows 'appA' and 'ai_3' is available but doesn't allow 'appA' + * In this situation 'appA' can access the allowed resource of 'ai_2' and the global resource of 'ai_3' + * + * @since_tizen 6.5 + * @param[in] app_info The application information + * @param[in] callback The 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 #APP_MANAGER_ERROR_NONE Successful + * @retval #APP_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #APP_MANAGER_ERROR_IO_ERROR I/O error + */ +int app_info_foreach_res_control(app_info_h app_info, app_info_res_control_cb callback, void *user_data); + /** * @} diff --git a/src/app_info.c b/src/app_info.c index f35d0bd..1abbcc4 100644 --- a/src/app_info.c +++ b/src/app_info.c @@ -67,6 +67,11 @@ typedef struct _foreach_category_ { void *user_data; } foreach_category_context_s; +typedef struct _foreach_res_control_ { + app_info_res_control_cb callback; + void *user_data; +} foreach_res_control_context_s; + static int app_info_convert_str_property(const char *property, char **converted_property) { if (property == NULL) @@ -245,6 +250,25 @@ static int app_info_foreach_app_info_cb(pkgmgrinfo_appinfo_h handle, void *cb_da return PMINFO_R_ERROR; } +static int app_info_foreach_res_control_cb(const char *res_type, + const char *min_res_version, const char *max_res_version, + const char *auto_close, void *user_data) +{ + foreach_res_control_context_s *foreach_context = user_data; + bool iteration_next = true; + + if (res_type == NULL) + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + iteration_next = foreach_context->callback(res_type, min_res_version, + max_res_version, auto_close, + foreach_context->user_data); + if (iteration_next == true) + return PMINFO_R_OK; + + return PMINFO_R_ERROR; +} + int app_info_foreach_app_info(app_manager_app_info_cb callback, void *user_data) { foreach_context_s foreach_context = { @@ -921,3 +945,21 @@ API int app_info_metadata_filter_foreach(app_info_metadata_filter_h handle, app_ return APP_MANAGER_ERROR_NONE; } +API int app_info_foreach_res_control(app_info_h app_info, app_info_res_control_cb callback, void *user_data) +{ + int retval = 0; + + if (app_info == NULL || callback == NULL) + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + + foreach_res_control_context_s foreach_context = { + .callback = callback, + .user_data = user_data, + }; + + retval = pkgmgrinfo_appinfo_foreach_res_control(app_info->pkg_app_info, app_info_foreach_res_control_cb, &foreach_context); + if (retval < 0) + return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); + + return APP_MANAGER_ERROR_NONE; +}