Add api for resource package add_api_for_resource_package
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 7 Jan 2021 09:42:00 +0000 (18:42 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 21 Apr 2021 06:03:27 +0000 (15:03 +0900)
Change-Id: I647c3d0086c52f2fd3323d1f1fd5bec96e8b48c5
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
include/pkgmgr-info.h
include/pkgmgrinfo_basic.h
include/pkgmgrinfo_type.h
src/appinfo_internal.c
src/manager/pkginfo_manager.h
src/pkginfo_internal.c
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_basic.c
src/pkgmgrinfo_pkginfo.c
src/pkgmgrinfo_private.h

index b2f349ceace9ff7fbb0853885b5ce887fe64c8c5..263f29aa87fc74edde80dbf01e50d5d53e8c71eb 100644 (file)
@@ -1647,6 +1647,78 @@ static int get_csc_path(const char *pkgid)
  */
 int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path);
 
+/**
+ * @fn int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle, char **res_type)
+ * @brief      This API gets the resource type of package
+ *
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  handle          pointer to package info handle
+ * @param[out] res_type        pointer to hold resource type of package
+ * @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
+ * @code
+static int get_res_type(const char *pkgid)
+{
+       int ret = 0;
+       char *res_type = 0;
+       pkgmgrinfo_pkginfo_h handle;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+
+       ret = pkgmgrinfo_pkginfo_get_res_type(handle, &res_type);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return -1;
+       }
+       printf("res_type : %s\n", res_type);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle, char **res_type);
+
+/**
+ * @fn int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle, char **res_version)
+ * @brief      This API gets the resource version of package
+ *
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  handle          pointer to package info handle
+ * @param[out] res_version     pointer to hold resource type of package
+ * @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
+ * @code
+static int get_res_version(const char *pkgid)
+{
+       int ret = 0;
+       char *res_version = 0;
+       pkgmgrinfo_pkginfo_h handle;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+
+       ret = pkgmgrinfo_pkginfo_get_res_version(handle, &res_version);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return -1;
+       }
+       printf("res_version : %s\n", res_version);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle, char **res_version);
+
 /**
  * @fn int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
  * @brief      This API gets the support_mode of package
@@ -4250,6 +4322,52 @@ int pkgmgrinfo_appinfo_foreach_background_category(pkgmgrinfo_appinfo_h handle,
 int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
                pkgmgrinfo_app_splash_screen_list_cb splash_screen_func, void *user_data);
 
+/**
+ * @fn int pkgmgrinfo_appinfo_foreach_res_control(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_res_control_list_cb res_control_func, void *user_data);
+ * @brief      This API gets the list of resource control for a particular application
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ * @param[in]  handle                  pointer to the application info handle.
+ * @param[in]  res_control_func        callback function for list
+ * @param[in]  user_data               user data to be passed to callback function
+ * @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                pkgmgrinfo_appinfo_get_appinfo()
+ * @post       pkgmgrinfo_appinfo_destroy_appinfo()
+ * @code
+int res_control_func(const char *res_type,
+               const char *min_res_version, const char *max_res_version,
+               const char *auto_close, void *user_data)
+{
+       printf("res_type : %s\n", res_type);
+       return 0;
+}
+
+static int list_res_control(const char *appid, char *key)
+{
+       int ret = 0;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_foreach_res_control(handle, res_control_func, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_foreach_res_control(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_res_control_list_cb res_control_func,
+               void *user_data);
+
 /**
  * @fn int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
  * @brief      This API gets the application 'nodisplay' value from the app ID
@@ -6151,6 +6269,91 @@ int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
                pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
                void *user_data);
 
+/**
+ * @fn int pkgmgrinfo_pkginfo_foreach_res_allowed_package(pkgmgrinfo_pkginfo_h handle,
+               pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
+               void *user_data)
+ * @brief      This API gets the list of allowed package for a particular package
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ * @param[in]  handle                  pointer to the package info handle.
+ * @param[in]  res_allowed_package_cb  callback function for list
+ * @param[in]  user_data               user data to be passed to callback function
+ * @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                pkgmgrinfo_pkginfo_get_pkginfo()
+ * @post       pkgmgrinfo_pkginfo_destroy_pkginfo()
+ * @code
+int res_allowed_package_cb(const char *allowed_package,
+               const char *required_privilege, void *user_data)
+{
+       printf("allowed package : %s", allowed_package);
+       if (required_privilege)
+               printf("required privilege : %s", required_privilege);
+       return 0;
+}
+
+static int list_res_allowed_package(const char *package)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_foreach_res_allowed_package(handle, res_allowed_package_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_foreach_res_allowed_package(pkgmgrinfo_pkginfo_h handle,
+               pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
+               void *user_data);
+
+/**
+ * @fn int pkgmgrinfo_resinfo_foreach_resinfo(const char *res_type,
+               pkgmgrinfo_resinfo_list_cb resinfo_list_cb, void *user_data)
+ * @brief      This API gets the list of resource info for a particular resource type
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ * @param[in]  res_type        resource type
+ * @param[in]  resinfo_list_cb callback function for list
+ * @param[in]  user_data       user data to be passed to callback function
+ * @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       None
+ * @code
+int resinfo_list_cb(const char *package, const char *res_version, void *user_data)
+{
+       printf("package : %s, res_version : %s", package, res_version);
+       return 0;
+}
+
+static int list_resinfo(const char *res_type)
+{
+       int ret = 0;
+       ret = pkgmgrinfo_resinfo_foreach_resinfo(res_type, resinfo_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               return -1;
+       }
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_resinfo_foreach_resinfo(const char *res_type,
+               pkgmgrinfo_resinfo_list_cb resinfo_list_cb, void *user_data);
+
 /**
  * @fn int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, int flag, void *user_data)
  * @brief      This API gets list of installed packages using flag that used for masking package's information
index 02746ca6d78cf0dc5f7ff097782ea6ec121e9a6f..92f9be04efb003528e9227630aa4dc886a1f6ea5 100644 (file)
@@ -129,6 +129,18 @@ typedef struct dependency_x {
        char *required_version;
 } dependency_x;
 
+typedef struct res_allowed_package_x {
+       char *allowed_package;
+       char *required_privilege;
+} res_allowed_package_x;
+
+typedef struct res_control_x {
+       char *res_type;
+       char *min_res_version;
+       char *max_res_version;
+       char *auto_close;
+} res_control_x;
+
 typedef struct application_x {
        char *appid;    /*attr*/
        char *exec;     /*attr*/
@@ -193,6 +205,7 @@ typedef struct application_x {
        GList *background_category; /*element*/
        GList *appcontrol; /*element*/
        GList *splashscreens; /*element*/
+       GList *res_control; /*element*/
 } application_x;
 
 typedef struct package_x {
@@ -226,6 +239,8 @@ typedef struct package_x {
        char *external_path; /**< external storage path if exists, no xml part*/
        char *use_system_certs; /**< use system certificates, attr*/
        char *locale;   /*no xml part*/
+       char *res_type; /**< res type, attr*/
+       char *res_version;      /**< res version, attr*/
        GList *icon;            /**< package icon, element*/
        GList *label;           /**< package label, element*/
        GList *author;          /**< package author, element*/
@@ -239,6 +254,7 @@ typedef struct package_x {
        GList *deviceprofile;           /**< package device profile, element*/
        GList *dependencies;            /**< package dependencies, element*/
        GList *plugin;          /**< plugin execution list, no xml part*/
+       GList *res_allowed_packages;            /**< res allowed packages, element*/
 } package_x;
 
 typedef struct updateinfo_x {
index 39a8d0a4b8808861d810822c37c40f93513b783a..c7203db7d92c3d8ff6a916c2b9ace249f7942e42 100644 (file)
@@ -100,7 +100,8 @@ typedef enum {
        PMINFO_APPINFO_GET_APP_CONTROL = 0x0010,
        PMINFO_APPINFO_GET_METADATA = 0x0020,
        PMINFO_APPINFO_GET_SPLASH_SCREEN = 0x0040,
-       PMINFO_APPINFO_GET_ALL = 0x007F
+       PMINFO_APPINFO_GET_RES_CONTROL = 0x0080,
+       PMINFO_APPINFO_GET_ALL = 0x00FF
 } pkgmgrinfo_appinfo_get_option;
 
 typedef enum {
@@ -112,7 +113,8 @@ typedef enum {
        PMINFO_PKGINFO_GET_PRIVILEGE = 0x0020,
        PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE = 0x0040,
        PMINFO_PKGINFO_GET_DEPENDENCY = 0x0080,
-       PMINFO_PKGINFO_GET_ALL = 0x00FF
+       PMINFO_PKGINFO_GET_RES_INFO = 0x0100,
+       PMINFO_PKGINFO_GET_ALL = 0x01FF
 } pkgmgrinfo_pkginfo_get_option;
 
 /**
@@ -357,6 +359,41 @@ typedef int (*pkgmgrinfo_plugin_list_cb) (const char *pkgid, const char *appid,
                const char *plugin_type, const char *plugin_name,
                void *user_data);
 
+/**
+ * @fn int (*pkgmgrinfo_resinfo_list_cb) (const char *package, const char *res_version, void *user_data);
+ *
+ * @brief Specifies the type of function passed to pkgmgrinfo_resinfo_foreach_resinfo()
+ *
+ * @param[in] package the name of the package
+ * @param[in] res_version the version of the resource package
+ * @param[in] user_data user data passed to pkgmgrinfo_resinfo_foreach_resinfo()
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.\n
+ *
+ * @see  pkgmgrinfo_resinfo_foreach_resinfo()
+ */
+typedef int (*pkgmgrinfo_resinfo_list_cb) (
+               const char *package, const char *res_version, void *user_data);
+
+/**
+ * @fn int (*pkgmgrinfo_res_allowed_package_list_cb) (
+               const char *allowed_package, const char *required_privilege,
+               void *user_data);
+ *
+ * @brief Specifies the type of function passed to pkgmgrinfo_pkginfo_foreach_res_allowed_package()
+ *
+ * @param[in] allowed_package the name of the package
+ * @param[in] required_privilege the required privilege of the package
+ * @param[in] user_data user data passed to pkgmgrinfo_pkginfo_foreach_res_allowed_package()
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.\n
+ *
+ * @see  pkgmgrinfo_pkginfo_foreach_res_allowed_package()
+ */
+typedef int (*pkgmgrinfo_res_allowed_package_list_cb) (
+               const char *allowed_package, const char *required_privilege,
+               void *user_data);
+
 /**
  * @fn int (*pkgmgrinfo_app_metadata_list_cb) (const char *metadata_key, const char *metadata_value, void *user_data)
  *
@@ -446,6 +483,10 @@ typedef int (*pkgmgrinfo_app_splash_screen_list_cb)(const char *src,
                const char *indicatordisplay, const char *operation,
                const char *color_depth, void *user_data);
 
+typedef int (*pkgmgrinfo_app_res_control_list_cb) (const char *res_type,
+               const char *min_res_version, const char *max_res_version,
+               const char *auto_close, void *user_data);
+
 
 
 /**
index 006fd7884fff091f302cb4fc3f8705f5ee76c3b1..f43940d1e229e95115addd1c1ed743e48defdf24 100644 (file)
@@ -246,6 +246,51 @@ static int _appinfo_get_category(sqlite3 *db,
        return PMINFO_R_OK;
 }
 
+static int _appinfo_get_res_control(sqlite3 *db, const char *appid,
+               GList **res_control)
+{
+       static const char query_raw[] =
+               "SELECT res_type, min_res_version, max_res_version, auto_close "
+               "FROM package_app_res_control WHERE app_id=%Q";
+       int ret;
+       char *query;
+       sqlite3_stmt *stmt;
+       int idx;
+       res_control_x *info;
+
+       query = sqlite3_mprintf(query_raw, appid);
+       if (query == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               info = calloc(1, sizeof(res_control_x));
+               if (info == NULL) {
+                       LOGE("out of memory");
+                       sqlite3_finalize(stmt);
+                       return PMINFO_R_ERROR;
+               }
+               idx = 0;
+               _save_column_str(stmt, idx++, &info->res_type);
+               _save_column_str(stmt, idx++, &info->min_res_version);
+               _save_column_str(stmt, idx++, &info->max_res_version);
+               _save_column_str(stmt, idx++, &info->auto_close);
+               *res_control = g_list_prepend(*res_control, info);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return PMINFO_R_OK;
+}
+
 static GList *__get_background_category(const char *value)
 {
        GList *category_list = NULL;
@@ -689,6 +734,14 @@ static int _appinfo_get_applications(sqlite3 *db, uid_t db_uid, uid_t uid,
                        }
                }
 
+               if (flag & PMINFO_APPINFO_GET_RES_CONTROL) {
+                       if (_appinfo_get_res_control(db, info->appid,
+                                               &info->res_control)) {
+                               ret = PMINFO_R_ERROR;
+                               goto catch;
+                       }
+               }
+
                if (is_check_storage &&
                                __appinfo_check_installed_storage(info) !=
                                                PMINFO_R_OK) {
index 41497ab8a3e95c04bc47276600176c26d71bbf99..d161dd86e4ac2cb74219303aab6aa2a7d4b0b882 100644 (file)
@@ -95,6 +95,9 @@ int _pkginfo_delete_certinfo(const char *pkgid);
 
 int _parser_clear_cache_memory_db(uid_t uid);
 
+int _pkginfo_get_depends_on(uid_t uid,
+               const char *pkgid, GList **dependencies);
+
 #ifdef __cplusplus
 }
 #endif
index 035477e3d3f8509c1d94d68ac13eebfb23916529..068550a7d622011cfdc31a1ac15ddbb278b1bc2e 100644 (file)
@@ -396,6 +396,91 @@ static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid,
        return PMINFO_R_OK;
 }
 
+static int _pkginfo_get_res_allowed_packages(sqlite3 *db, const char *pkgid,
+               GList **allowed_packages)
+{
+       static const char query_raw[] =
+               "SELECT DISTINCT allowed_package, required_privilege "
+               "FROM package_res_allowed_package WHERE package=%Q";
+       int ret;
+       char *query;
+       sqlite3_stmt *stmt;
+       res_allowed_package_x *allowed_package;
+
+       query = sqlite3_mprintf(query_raw, pkgid);
+       if (query == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               allowed_package = calloc(1, sizeof(res_allowed_package_x));
+               if (!allowed_package) {
+                       LOGE("failed to alloc memory");
+                       sqlite3_finalize(stmt);
+                       return PMINFO_R_ERROR;
+               }
+               _save_column_str(stmt, 0, &allowed_package->allowed_package);
+               _save_column_str(stmt, 1, &allowed_package->required_privilege);
+               *allowed_packages = g_list_prepend(
+                               *allowed_packages, (gpointer)allowed_package);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return PMINFO_R_OK;
+}
+
+static int _pkginfo_get_res_info(sqlite3 *db, const char *pkgid,
+               char **res_type, char **res_version,
+               GList **res_allowed_packages)
+{
+       static const char query_raw[] =
+               "SELECT DISTINCT res_type, res_version "
+               "FROM package_res_info WHERE package=%Q";
+       int ret;
+       char *query;
+       sqlite3_stmt *stmt;
+
+       query = sqlite3_mprintf(query_raw, pkgid);
+       if (query == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               sqlite3_finalize(stmt);
+               return PMINFO_R_OK;
+       }
+
+       _save_column_str(stmt, 0, res_type);
+       _save_column_str(stmt, 1, res_version);
+
+       if (_pkginfo_get_res_allowed_packages(db, pkgid,
+                       res_allowed_packages) != PMINFO_R_OK) {
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return PMINFO_R_OK;
+}
+
 static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
                pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
 {
@@ -609,6 +694,16 @@ static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
                        }
                }
 
+               if (flag & PMINFO_PKGINFO_GET_RES_INFO) {
+                       if (_pkginfo_get_res_info(db, info->package,
+                                       &info->res_type,
+                                       &info->res_version,
+                                       &info->res_allowed_packages) < 0) {
+                               ret = PMINFO_R_ERROR;
+                               goto catch;
+                       }
+               }
+
                if (is_check_storage &&
                                __pkginfo_check_installed_storage(info) !=
                                                PMINFO_R_OK) {
@@ -1623,6 +1718,53 @@ static int __insert_app_localized_info(sqlite3 *db, application_x *app)
        return 0;
 }
 
+static int __insert_app_res_control(sqlite3 *db, application_x *app)
+{
+       static const char query[] =
+               "INSERT INTO package_app_res_control (app_id, res_type,"
+               "  min_res_version, max_res_version, auto_close) "
+               "VALUES (?, ?, ?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *tmp;
+       res_control_x *rc;
+
+       if (app->res_control == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (tmp = app->res_control; tmp; tmp = tmp->next) {
+               rc = (res_control_x *)tmp->data;
+               if (rc == NULL)
+                       continue;
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, app->appid);
+               __BIND_TEXT(db, stmt, idx++, rc->res_type);
+               __BIND_TEXT(db, stmt, idx++, rc->min_res_version);
+               __BIND_TEXT(db, stmt, idx++, rc->max_res_version);
+               __BIND_TEXT(db, stmt, idx++, rc->auto_close);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
 {
        static const char query[] =
@@ -2029,6 +2171,92 @@ static int __convert_background_category(GList *category_list)
        return ret;
 }
 
+static int __insert_package_res_info_allowed_package(sqlite3 *db,
+               const char *pkgid, GList *rap_list)
+{
+       static const char query[] =
+               "INSERT INTO package_res_allowed_package (package,"
+               "  allowed_package, required_privilege) VALUES (?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *tmp;
+       res_allowed_package_x *rap;
+
+       if (rap_list == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (tmp = rap_list; tmp; tmp = tmp->next) {
+               rap = (res_allowed_package_x *)tmp->data;
+               if (rap == NULL)
+                       continue;
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, pkgid);
+               __BIND_TEXT(db, stmt, idx++, rap->allowed_package);
+               __BIND_TEXT(db, stmt, idx++, rap->required_privilege);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+static int __insert_package_res_info(sqlite3 *db, manifest_x *mfx)
+{
+       static const char query[] =
+               "INSERT INTO package_res_info (package, res_type,"
+               "  res_version) VALUES (?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+
+       if (mfx->res_type == NULL || mfx->res_version == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       idx = 1;
+       __BIND_TEXT(db, stmt, idx, mfx->package);
+       __BIND_TEXT(db, stmt, idx++, mfx->res_type);
+       __BIND_TEXT(db, stmt, idx, mfx->res_version);
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_DONE) {
+               _LOGE("step failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       if (__insert_package_res_info_allowed_package(db, mfx->package,
+                       mfx->res_allowed_packages) < 0) {
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
 {
        static const char query[] =
@@ -2179,6 +2407,10 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                        sqlite3_finalize(stmt);
                        return -1;
                }
+               if (__insert_app_res_control(db, app)) {
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
        }
 
        sqlite3_finalize(stmt);
@@ -2372,6 +2604,8 @@ static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
                return -1;
        if (__insert_package_dependency_info(db, mfx))
                return -1;
+       if (__insert_package_res_info(db, mfx))
+               return -1;
 
        return 0;
 }
index 801318b856a8fdfe6fd6e4bb8d666f5af0e6449e..6def623b189d34657583dd0444ade4ab28f1ec71 100644 (file)
@@ -431,6 +431,30 @@ static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
        return splashscreen;
 }
 
+static gpointer __copy_res_control(gconstpointer src, gpointer data)
+{
+       res_control_x *tmp = (res_control_x *)src;
+       res_control_x *res_control;
+
+       res_control = (res_control_x *)calloc(1, sizeof(res_control_x));
+       if (res_control == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->res_type)
+               res_control->res_type = strdup(tmp->res_type);
+       if (tmp->min_res_version)
+               res_control->min_res_version = strdup(tmp->min_res_version);
+       if (tmp->max_res_version)
+               res_control->max_res_version = strdup(tmp->max_res_version);
+       if (tmp->auto_close)
+               res_control->auto_close = strdup(tmp->auto_close);
+
+       return res_control;
+}
+
 static int _appinfo_copy_appinfo(
                application_x **application, application_x *data)
 {
@@ -583,6 +607,14 @@ static int _appinfo_copy_appinfo(
                return PMINFO_R_ERROR;
        }
 
+       ret = 0;
+       app_info->res_control = g_list_copy_deep(data->res_control, __copy_res_control, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
        *application = app_info;
 
        return PMINFO_R_OK;
@@ -1883,6 +1915,36 @@ API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_foreach_res_control(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_res_control_list_cb res_control_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(res_control_func == NULL, PMINFO_R_EINVAL,
+                       "Callback function is NULL");
+       int ret = -1;
+       res_control_x *res_control;
+       GList *tmp;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->res_control; tmp; tmp = tmp->next) {
+               res_control = (res_control_x *)tmp->data;
+               if (res_control == NULL)
+                       continue;
+               ret = res_control_func(res_control->res_type,
+                               res_control->min_res_version,
+                               res_control->max_res_version,
+                               res_control->auto_close,
+                               user_data);
+               if (ret < 0)
+                       break;
+       }
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_is_nodisplay(
                pkgmgrinfo_appinfo_h handle, bool *nodisplay)
 {
index baec351fcc358a8910820495f29501bf8eb6322a..727d332d3d68fb6829747c9eadfb151ca87e701f 100644 (file)
@@ -111,6 +111,18 @@ static void __ps_free_plugin_info(gpointer data)
        free((void *)plugin);
 }
 
+static void __ps_free_res_allowed_packages(gpointer data)
+{
+       res_allowed_package_x *allowed_package = (res_allowed_package_x *)data;
+       if (allowed_package == NULL)
+               return;
+       if (allowed_package->allowed_package)
+               free((void *)allowed_package->allowed_package);
+       if (allowed_package->required_privilege)
+               free((void *)allowed_package->required_privilege);
+       free((void *)allowed_package);
+}
+
 static void __ps_free_appcontrol(gpointer data)
 {
        appcontrol_x *appcontrol = (appcontrol_x *)data;
@@ -313,6 +325,22 @@ static void __ps_free_dependency(gpointer data)
        free((void *)dependency);
 }
 
+static void __ps_free_res_control(gpointer data)
+{
+       res_control_x *res_control = (res_control_x *)data;
+       if (res_control == NULL)
+               return;
+       if (res_control->res_type)
+               free((void *)res_control->res_type);
+       if (res_control->min_res_version)
+               free((void *)res_control->min_res_version);
+       if (res_control->max_res_version)
+               free((void *)res_control->max_res_version);
+       if (res_control->auto_close)
+               free((void *)res_control->auto_close);
+       free((void *)res_control);
+}
+
 static void __ps_free_application(gpointer data)
 {
        application_x *application = (application_x *)data;
@@ -447,6 +475,8 @@ static void __ps_free_application(gpointer data)
        g_list_free_full(application->background_category, free);
        /*Free SplashScreen*/
        g_list_free_full(application->splashscreens, __ps_free_splashscreen);
+       /*Free res control*/
+       g_list_free_full(application->res_control, __ps_free_res_control);
 
        free((void *)application);
 }
@@ -552,6 +582,8 @@ API void pkgmgrinfo_basic_free_package(package_x *package)
        g_list_free_full(package->dependencies, __ps_free_dependency);
        /*Free Plugin execution history*/
        g_list_free_full(package->plugin, __ps_free_plugin_info);
+       /*Free resource allowed packages*/
+       g_list_free_full(package->res_allowed_packages, __ps_free_res_allowed_packages);
        free((void *)package);
 }
 
index 315166df0a6ed9d2ce393f6947e700ba8f46f7a9..b56382caa21ae655451b4239931fa599c124874d 100644 (file)
@@ -902,6 +902,42 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle, char **res_type)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(res_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL)
+               return PMINFO_R_ERROR;
+
+       if (info->pkg_info->res_type == NULL)
+               *res_type = "";
+       else
+               *res_type = (char *)info->pkg_info->res_type;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle, char **res_version)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(res_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL)
+               return PMINFO_R_ERROR;
+
+       if (info->pkg_info->res_version == NULL)
+               *res_version = "";
+       else
+               *res_version = (char *)info->pkg_info->res_version;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1511,6 +1547,38 @@ API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_foreach_res_allowed_package(
+               pkgmgrinfo_pkginfo_h handle,
+               pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
+               void *user_data)
+{
+       int ret;
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       GList *tmp;
+       res_allowed_package_x *res_allowed_package;
+
+       if (handle == NULL || res_allowed_package_cb == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->pkg_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->pkg_info->res_allowed_packages; tmp; tmp = tmp->next) {
+               res_allowed_package = (res_allowed_package_x *)tmp->data;
+               if (res_allowed_package == NULL)
+                       continue;
+               ret = res_allowed_package_cb(
+                               res_allowed_package->allowed_package,
+                               res_allowed_package->required_privilege, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
 int __compare_package_version(const char *version, int *major,
                int *minor, int *macro, int *nano)
 {
@@ -1633,3 +1701,97 @@ API int pkgmgrinfo_compare_package_version(const char *current_version,
 
        return PMINFO_R_OK;
 }
+
+static void _free_resinfo(gpointer data)
+{
+       res_info *info = (res_info *)data;
+       if (info == NULL)
+               return;
+       if (info->package)
+               free((void *)info->package);
+       if (info->res_version)
+               free((void *)info->res_version);
+       free((void *)info);
+}
+
+API int pkgmgrinfo_resinfo_foreach_resinfo(const char *res_type,
+               pkgmgrinfo_resinfo_list_cb resinfo_list_cb, void *user_data)
+{
+       int ret;
+       int idx = 0;
+       char *dbpath;
+       sqlite3 *db;
+       sqlite3_stmt *stmt = NULL;
+       res_info *info;
+       GList *res_info_list = NULL;
+       GList *tmp_list;
+
+       static const char query[] =
+                       "SELECT package, res_version FROM "
+                       "package_res_info WHERE res_type=?";
+
+       if (!res_type || !resinfo_list_cb) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       dbpath = getUserPkgParserDBPathUID(_getuid());
+       if (dbpath == NULL) {
+               _LOGE("Failed to get db path");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       if (ret != SQLITE_OK) {
+               _LOGD("failed to open db(%s): %d", dbpath, ret);
+               free(dbpath);
+               return PMINFO_R_ERROR;
+       }
+       free(dbpath);
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               ret = PMINFO_R_ERROR;
+               goto catch;
+       }
+
+       ret = sqlite3_bind_text(stmt, ++idx, res_type, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               ret = PMINFO_R_ERROR;
+               goto catch;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               info = calloc(1, sizeof(res_info));
+               if (info == NULL)  {
+                       _LOGE("out of memory");
+                       ret = PMINFO_R_ERROR;
+                       goto catch;
+               }
+               idx = 0;
+               _save_column_str(stmt, idx++, &info->package);
+               _save_column_str(stmt, idx++, &info->res_version);
+               res_info_list = g_list_prepend(res_info_list, info);
+       }
+
+       for (tmp_list = res_info_list; tmp_list != NULL;
+                       tmp_list = tmp_list->next) {
+               info = (res_info *)tmp_list->data;
+               if (!info)
+                       continue;
+               ret = resinfo_list_cb(info->package, info->res_version,
+                               user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+       g_list_free_full(res_info_list, _free_resinfo);
+
+       return ret;
+}
index be1bbf934afaf2c11559f12ea025007017095a23..7ee7c53ebd019158cc64564d4561a6c8f8d253d0 100644 (file)
@@ -310,6 +310,11 @@ typedef struct _pkg_plugin_set {
        get_pkg_detail_info_from_package;
 } pkg_plugin_set;
 
+typedef struct res_info {
+       char *package;
+       char *res_version;
+} res_info;
+
 pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property);
 pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property);
 pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property);