Add api for resource package 24/260824/8
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 5 Jul 2021 08:34:43 +0000 (17:34 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 22 Jul 2021 07:50:58 +0000 (16:50 +0900)
Change-Id: I95a619776dfe160ceabc869f2a5f2337653fa454
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
include/app_info.h
src/app_info.c

index 6ed44da..70b4bba 100644 (file)
@@ -162,6 +162,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
  * @remarks The @a app_info should be released using app_info_destroy().
@@ -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 *
+ *            <table>
+ *            <tr>
+ *             <th> res_type </th>
+ *             <th> min_res_version </th>
+ *             <th> max_res_version </th>
+ *            </tr>
+ *            <tr>
+ *             <td> ai_model </td>
+ *             <td> 1.0.0 </td>
+ *             <td> 2.0.0 </td>
+ *            </tr>
+ *            </table>
+ *          and there are resource packages with res_type 'ai_model' like below
+ *            <table>
+ *            <tr>
+ *             <th> package </th>
+ *             <th> res_type </th>
+ *             <th> res_version </th>
+ *             <th> allowes 'appA'? </th>
+ *            </tr>
+ *            <tr>
+ *             <td> ai_1 </td>
+ *             <td> ai_model </td>
+ *             <td> 0.0.1 </td>
+ *             <td> yes </td>
+ *            </tr>
+ *            <tr>
+ *             <td> ai_2 </td>
+ *             <td> ai_model </td>
+ *             <td> 1.0.0 </td>
+ *             <td> yes </td>
+ *            </tr>
+ *            <tr>
+ *             <td> ai_3 </td>
+ *             <td> ai_model </td>
+ *             <td> 2.0.0 </td>
+ *             <td> no </td>
+ *            </tr>
+ *            </table>
+ *          '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);
+
 
 /**
 * @}
index f35d0bd..1abbcc4 100644 (file)
@@ -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;
+}