From aef33ab4eaef3b1b39045e4d2695a0cee25b230b Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 23 Feb 2021 16:50:30 +0900 Subject: [PATCH] Update pkgmgr-info APIs - Fix build error of getting localed label API. - Implement get datacontrol info API Signed-off-by: Junghyun Yeon --- src/manager/pkginfo_manager.cc | 46 ++++++++++++++++++++++++++++++++++ src/manager/pkginfo_manager.h | 3 +++ src/pkgmgrinfo_appinfo.c | 56 ++---------------------------------------- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/manager/pkginfo_manager.cc b/src/manager/pkginfo_manager.cc index d2c14fd..5fdb054 100644 --- a/src/manager/pkginfo_manager.cc +++ b/src/manager/pkginfo_manager.cc @@ -141,4 +141,50 @@ extern "C" EXPORT_API char *_appinfo_get_localed_label( } return label; +} + +int _appinfo_get_datacontrol_info(const char *providerid, + const char *type, uid_t uid, char **appid, char **access) { + char *query = nullptr; + query = sqlite3_mprintf("SELECT app_id, access FROM " + "package_app_data_control WHERE " + "providerid=%Q AND type=%Q", providerid, type); + if (query == nullptr) { + LOG(ERROR) << "Out of memory"; + return PMINFO_R_ERROR; + } + + std::shared_ptr parcelable( + new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query))); + + pkgmgr_client::PkgInfoClient client(parcelable, uid); + if (!client.SendRequest()) + return PMINFO_R_ERROR; + // TODO: deliver rawdata to reqhandler directly if server is not working + + std::shared_ptr return_parcel( + std::static_pointer_cast( + client.GetResultParcel())); + tizen_base::Parcel parcel; + parcel.ReadParcelable(return_parcel.get()); + sqlite3_free(query); + // result_list is vector of string vector + auto result_list = return_parcel->GetResult(); + if (result_list.size() == 0) + return PMINFO_R_ENOENT; + for (auto result : result_list) { + if (result.size() != 2) + return PMINFO_R_ERROR; + if (result.front().empty() || result.front().size() == 0 || + result.back().empty() || result.back().size() == 0) + return PMINFO_R_ERROR; + *appid = strdup(result.front().c_str()); + *access = strdup(result.back().c_str()); + if (*appid == nullptr || *access == nullptr) { + LOG(ERROR) << "Out of memory"; + return PMINFO_R_ERROR; + } + } + + return PMINFO_R_OK; } \ No newline at end of file diff --git a/src/manager/pkginfo_manager.h b/src/manager/pkginfo_manager.h index 63931c4..f10897d 100644 --- a/src/manager/pkginfo_manager.h +++ b/src/manager/pkginfo_manager.h @@ -36,6 +36,9 @@ int _appinfo_get_applications(uid_t db_uid, uid_t uid, char *_appinfo_get_localed_label(const char *appid, const char *locale, uid_t uid); +int _appinfo_get_datacontrol_info(const char *providerid, + const char *type, uid_t uid, char **appid, char **access); + #ifdef __cplusplus } #endif diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index 7d0c88c..460c7f1 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -939,29 +939,12 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) return PMINFO_R_OK; } -static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) -{ - char *query = NULL; - - query = sqlite3_mprintf( - "SELECT app_label FROM package_app_localized_info " - "WHERE app_id=%Q AND app_locale=%Q", appid, locale); - if (query == NULL) { - _LOGE("Out of memory"); - return NULL; - } - - // TODO: need to use pkginfo-client APIs - sqlite3_free(query); - return NULL; -} - API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label) { char *val; retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL"); - val = _appinfo_get_localed_label(); + val = _appinfo_get_localed_label(appid, locale, uid); if (val == NULL) return PMINFO_R_ERROR; @@ -1450,36 +1433,6 @@ API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int * return PMINFO_R_OK; } -static int _appinfo_get_datacontrol_info(const char *providerid, - const char *type, char **appid, char **access) -{ - char *query = NULL; - - - query = sqlite3_mprintf("SELECT app_id, access FROM package_app_data_control " - "WHERE providerid=%Q AND type=%Q", providerid, type); - if (query == NULL) { - LOGE("Out of memory"); - return PMINFO_R_ERROR; - } - - // TODO: need to use pkginfo-client APIs - sqlite3_free(query); - return PMINFO_R_OK; -} - -static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid, - const char *providerid, const char *type, - char **appid, char **access) -{ - int ret; - - ret = _appinfo_get_datacontrol_info(providerid, type, appid, - access); - - return ret; -} - API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access) { @@ -1491,12 +1444,7 @@ API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, return PMINFO_R_EINVAL; } - ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid, - type, appid, access); - if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) - ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid, - type, appid, access); - + ret = _appinfo_get_datacontrol_info(providerid, type, uid, appid, access); /* FIXME: It should return PMINFO_R_ENOENT but to keep previous * implementation, return PMINFO_R_ERROR. This should be * modified later... -- 2.7.4