From 53659b28bcd4acdd918bd50c79595740fc0042be Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 7 Jan 2019 18:41:34 +0900 Subject: [PATCH] Add attribute 'id' on app-control element Change-Id: I3a44c4610e8831e3597a7d9b511f5e060dfbed88 Signed-off-by: Hwankyu Jhun --- include/pkgmgr-info.h | 26 ++++++++++++++ include/pkgmgrinfo_basic.h | 1 + include/pkgmgrinfo_type.h | 18 ++++++++++ parser/manifest.xsd.in | 1 + parser/manifest.xsd.ref | 1 + parser/src/pkgmgr_parser_db.c | 5 +-- parser/src/pkgmgr_parser_db_queries.h | 1 + pkg_db_version.txt.in | 2 +- src/pkgmgrinfo_appinfo.c | 66 +++++++++++++++++++++++++++++++++-- src/pkgmgrinfo_basic.c | 7 ++++ 10 files changed, 123 insertions(+), 5 deletions(-) diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index 9be5008..1b5c965 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -5742,6 +5742,32 @@ int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filte pkgmgrinfo_app_list_cb app_cb, void *user_data); int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle, pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid); + +/** + * @fn int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, void *user_data); + * @fn int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, void *user_data); + * @brief This API gets the list of app-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] appcontrol_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() + */ +int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data); +int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data); /** * @fn int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle) * @brief This API creates the package cert information handle to get data from db. diff --git a/include/pkgmgrinfo_basic.h b/include/pkgmgrinfo_basic.h index deb93ab..b7bb44e 100644 --- a/include/pkgmgrinfo_basic.h +++ b/include/pkgmgrinfo_basic.h @@ -82,6 +82,7 @@ typedef struct appcontrol_x { char *uri; char *mime; char *visibility; + char *id; GList *privileges; } appcontrol_x; diff --git a/include/pkgmgrinfo_type.h b/include/pkgmgrinfo_type.h index a2404f7..f4e49a3 100644 --- a/include/pkgmgrinfo_type.h +++ b/include/pkgmgrinfo_type.h @@ -353,6 +353,24 @@ typedef int (*pkgmgrinfo_app_metadata_list_cb) (const char *metadata_key, */ typedef int (*pkgmgrinfo_app_control_list_cb) (const char *operation, const char *uri, const char *mime, void *user_data); +/** + * @fn int (*pkgmgrinfo_app_control_list_cb_v2) (const char *operation, const char *uri, const char *mime, const char *id, void *user_data) + * + * @brief Specifies the type of function passed to pkgmgrinfo_appinfo_foreach_appcontrol_info() + * + * @param[in] operation The operation of the app-control + * @param[in] uri The URI of the app-control + * @param[in] mime The MIME-Type of the app-control + * @param[in] id The ID of the app-control + * @param[in] user_data The user data passed from pkgmgrinfo_appinfo_foreach_appcontrol_v2() + * + * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.\n + * + * @see pkgmgrinfo_appinfo_foreach_appcontrol_v2() + */ +typedef int (*pkgmgrinfo_app_control_list_cb_v2) (const char *operation, + const char *uri, const char *mime, const char *id, + void *user_data); /** * @fn int (*pkgmgrinfo_app_background_category_list_cb) (const char *category_name, void *user_data) diff --git a/parser/manifest.xsd.in b/parser/manifest.xsd.in index 69aa09c..c8a624a 100644 --- a/parser/manifest.xsd.in +++ b/parser/manifest.xsd.in @@ -284,6 +284,7 @@ + diff --git a/parser/manifest.xsd.ref b/parser/manifest.xsd.ref index f50d80e..253eef4 100644 --- a/parser/manifest.xsd.ref +++ b/parser/manifest.xsd.ref @@ -346,6 +346,7 @@ + diff --git a/parser/src/pkgmgr_parser_db.c b/parser/src/pkgmgr_parser_db.c index 62ffed3..b663211 100644 --- a/parser/src/pkgmgr_parser_db.c +++ b/parser/src/pkgmgr_parser_db.c @@ -748,8 +748,8 @@ static int __insert_appcontrol_info(sqlite3 *db, application_x *app) { static const char query[] = "INSERT INTO package_app_app_control (app_id, app_control," - " visibility) " - "VALUES (?, ?, ?)"; + " visibility, app_control_id) " + "VALUES (?, ?, ?, ?)"; int ret; sqlite3_stmt *stmt; int idx; @@ -781,6 +781,7 @@ static int __insert_appcontrol_info(sqlite3 *db, application_x *app) __BIND_TEXT(db, stmt, idx++, app->appid); __BIND_TEXT(db, stmt, idx++, app_control); __BIND_TEXT(db, stmt, idx++, ac->visibility); + __BIND_TEXT(db, stmt, idx++, ac->id); ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { diff --git a/parser/src/pkgmgr_parser_db_queries.h b/parser/src/pkgmgr_parser_db_queries.h index 531f6a2..282918b 100644 --- a/parser/src/pkgmgr_parser_db_queries.h +++ b/parser/src/pkgmgr_parser_db_queries.h @@ -156,6 +156,7 @@ " app_id TEXT NOT NULL,\n" \ " app_control TEXT NOT NULL,\n" \ " visibility TEXT NOT NULL DEFAULT 'local-only',\n" \ + " app_control_id TEXT NOT NULL DEFAULT 'no-name-app-control',\n" \ " PRIMARY KEY(app_id,app_control)\n" \ " FOREIGN KEY(app_id)\n" \ " REFERENCES package_app_info(app_id) ON DELETE CASCADE)" diff --git a/pkg_db_version.txt.in b/pkg_db_version.txt.in index dabc267..2085262 100644 --- a/pkg_db_version.txt.in +++ b/pkg_db_version.txt.in @@ -1 +1 @@ -30002 +30003 diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index 232d75e..7d0f074 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -155,7 +155,7 @@ static int _appinfo_get_category(sqlite3 *db, const char *appid, } static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str, - char *visibility) + char *visibility, char *id) { char *dup; char *token; @@ -187,6 +187,7 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str, if (token && strcmp(token, "NULL")) ac->mime = strdup(token); ac->visibility = strdup(visibility); + ac->id = strdup(id); *appcontrol = g_list_append(*appcontrol, ac); } while ((token = strtok_r(NULL, ";", &ptr))); @@ -204,6 +205,7 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, sqlite3_stmt *stmt; char *str; char *visibility; + char *id; query = sqlite3_mprintf(query_raw, appid); if (query == NULL) { @@ -221,12 +223,15 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, while (sqlite3_step(stmt) == SQLITE_ROW) { str = NULL; visibility = NULL; + id = NULL; _save_column_str(stmt, 0, &str); _save_column_str(stmt, 0, &visibility); + _save_column_str(stmt, 0, &id); /* TODO: revise */ - __parse_appcontrol(appcontrol, str, visibility); + __parse_appcontrol(appcontrol, str, visibility, id); free(str); free(visibility); + free(id); } sqlite3_finalize(stmt); @@ -3623,3 +3628,60 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, *status = _get_bool_value(val); return PMINFO_R_OK; } + +API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; + GList *tmp; + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || + !strcasecmp(appcontrol->visibility, "remote-only")) + continue; + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, + appcontrol->mime, appcontrol->id, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2( + pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; + GList *tmp; + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || + !strcasecmp(appcontrol->visibility, "local-only")) + continue; + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, + appcontrol->mime, appcontrol->id, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} diff --git a/src/pkgmgrinfo_basic.c b/src/pkgmgrinfo_basic.c index 330b1da..c5c95a8 100644 --- a/src/pkgmgrinfo_basic.c +++ b/src/pkgmgrinfo_basic.c @@ -99,6 +99,13 @@ static void __ps_free_appcontrol(gpointer data) /*Free Mime*/ if (appcontrol->mime) free((void *)appcontrol->mime); + /*Free Visibility*/ + if (appcontrol->visibility) + free((void *)appcontrol->visibility); + /*Free Id*/ + if (appcontrol->id) + free((void *)appcontrol->id); + /*Free Privileges*/ if (appcontrol->privileges) g_list_free_full(appcontrol->privileges, free); free((void *)appcontrol); -- 2.7.4