From 7493f12433c18af2140b39265f7521274c6a5eaa Mon Sep 17 00:00:00 2001 From: "j-h.choi" Date: Wed, 23 Oct 2024 15:10:10 +0900 Subject: [PATCH] Add API to check if package is resource control Change-Id: I371e7e48b77e33216cace3fdc0731848428fb26f --- NativeLauncher/inc/utils.h | 21 ++++++ NativeLauncher/tool/ni_common.cc | 4 ++ NativeLauncher/util/utils.cc | 107 +++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 3c07d85..43aada0 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -352,4 +352,25 @@ std::string getResourcePaths(const std::string& rootPath); */ bool isRPK(const std::string& pkgId); +/** + * @brief get package ID from root path + * @param[in] root Path + * @return std::string pkgId + */ +std::string getPkgId(const std::string& rootPath); + +/** + * @brief get app Id list + * @param[in] pkgId package ID + * @return std::vector appId list + */ +std::vector getAppList(const std::string& pkgId); + +/** + * @brief check the package has resource control + * @param[in] pkgId package ID + * @return return true when package has resource control + */ +bool hasResControl(const std::string& pkgId); + #endif /* __UTILS_H__ */ diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 41aa18d..6fbddbf 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -1100,6 +1100,10 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt) opt->flags |= NI_FLAGS_APPNI; + if (hasResControl(getPkgId(rootPath))) { + opt->flags &= ~NI_FLAGS_INPUT_BUBBLE; + } + if (isReadOnlyArea(rootPath)) { opt->flags |= NI_FLAGS_APP_UNDER_RO_AREA; opt->flags |= NI_FLAGS_NO_PIPELINE; diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index ad9ec2f..a7c90e9 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -913,3 +913,110 @@ bool isRPK(const std::string& pkgId) return false; } +std::string getPkgId(const std::string& rootPath) +{ + std::vector paths; + std::istringstream ss(rootPath); + std::string token; + + while (std::getline(ss, token, PATH_SEPARATOR)) { + if (token != "") { + paths.push_back(token); + } + } + + if (paths.size() != 0) { + return paths.back(); + } + + return ""; +} + +static int appListCb(pkgmgrinfo_appinfo_h handle, void *user_data) +{ + int ret = 0; + char *appId = 0; + + ret = pkgmgrinfo_appinfo_get_appid(handle, &appId); + if (ret != PMINFO_R_OK) { + _SERR("Failed to get appId"); + return -1; + } + + std::vector *appList = (std::vector *)user_data; + appList->push_back(appId); + + return 0; +} + +std::vector getAppList(const std::string& pkgId) +{ + std::vector appsList; + uid_t uid = 0; + int ret = 0; + + if (pkgmgr_installer_info_get_target_uid(&uid) < 0) { + _ERR("Failed to get UID"); + return appsList; + } + + pkgmgrinfo_pkginfo_h pkg_handle; + ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle); + if (ret != 0) { + return appsList; + } + + ret = pkgmgrinfo_appinfo_get_usr_list(pkg_handle, PMINFO_ALL_APP, appListCb, &appsList, uid); + if (ret != PMINFO_R_OK) { + _ERR("pkgmgrinfo_appinfo_get_usr_list() is failed"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle); + return appsList; + } + + pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle); + + return appsList; +} + +static int resControlCb(const char* res_type, const char* min_res_version, const char* max_res_version, const char* auto_close, void* user_data) +{ + bool* exists = static_cast(user_data); + *exists = true; + return 0; +} + +bool hasResControl(const std::string& pkgId) +{ + bool resControl = false; + int ret = 0; + + if (pkgId == "") { + return false; + } + + for (auto& appId : getAppList(pkgId)) { + bool flag = false; + pkgmgrinfo_appinfo_h app_handle; + ret = pkgmgrGetAppInfo(appId, &app_handle); + if (ret != 0) { + return false; + } + + ret = pkgmgrinfo_appinfo_foreach_res_control(app_handle, resControlCb, &flag); + if (ret != PMINFO_R_OK) { + _ERR("pkgmgrinfo_appinfo_foreach_res_control() is failed"); + pkgmgrinfo_appinfo_destroy_appinfo(app_handle); + return false; + } + + if (flag) { + resControl = true; + break; + } + + pkgmgrinfo_appinfo_destroy_appinfo(app_handle); + } + + return resControl; +} + -- 2.34.1