From: ilho kim Date: Tue, 21 Mar 2023 05:35:38 +0000 (+0900) Subject: Add APIs for getting path related Resource Control X-Git-Tag: accepted/tizen/unified/20230331.225108~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98ac1743f8f5c99c5ab4c9ff9ddd314ef3a86f2c;p=platform%2Fcore%2Fappfw%2Faul-1.git Add APIs for getting path related Resource Control - add aul_get_app_res_control_allowed_resource_path() - add aul_get_app_res_control_global_resource_path() Change-Id: I70ff0a2f98f100ef8198090d4b3ec3f8eb81599f Signed-off-by: ilho kim --- diff --git a/aul/app_info/directory_info.cc b/aul/app_info/directory_info.cc index 846eff9..f7314d2 100644 --- a/aul/app_info/directory_info.cc +++ b/aul/app_info/directory_info.cc @@ -39,6 +39,8 @@ constexpr const char kSharedTrustedDir[] = "shared/trusted/"; constexpr const char kSharedResourceDir[] = "shared/res/"; constexpr const char kAppRWDir[] = "apps_rw/"; constexpr const char kLightUserSwitchModeDefault[] = "default"; +constexpr const char kResControlAllowedDir[] = "res/mount/allowed/"; +constexpr const char kResControlGlobalDir[] = "res/mount/global/"; std::string GetRWPath(const std::string& pkg_id, uid_t uid) { tzplatform_set_user(uid); @@ -102,12 +104,25 @@ DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedTrustedPath( return *this; } +DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlAllowedPath( + std::string res_control_allowed_res_path) { + res_control_allowed_res_path_ = std::move(res_control_allowed_res_path); + return *this; +} + +DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlGlobalPath( + std::string res_control_global_res_path) { + res_control_global_res_path_ = std::move(res_control_global_res_path); + return *this; +} + DirectoryInfo::Builder::operator DirectoryInfo*() { return new (std::nothrow) DirectoryInfo(std::move(root_path_), std::move(data_path_), std::move(cache_path_), std::move(resource_path_), std::move(tep_resource_path_), std::move(shared_data_path_), std::move(shared_resource_path_), - std::move(shared_trusted_path_)); + std::move(shared_trusted_path_), std::move(res_control_allowed_res_path_), + std::move(res_control_global_res_path_)); } DirectoryInfo* DirectoryInfo::Get(const std::string app_id, @@ -125,7 +140,9 @@ DirectoryInfo* DirectoryInfo::Get(const std::string app_id, .SetTepResourcePath(GetPath(root_path, kTepResourceDir)) .SetSharedDataPath(GetPath(rw_path, kSharedDataDir)) .SetSharedResourcePath(GetPath(root_path, kSharedResourceDir)) - .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir)); + .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir)) + .SetResControlAllowedPath(GetPath(root_path, kResControlAllowedDir)) + .SetResControlGlobalPath(GetPath(root_path, kResControlGlobalDir)); } DirectoryInfo* DirectoryInfo::Get() { @@ -144,7 +161,9 @@ DirectoryInfo::DirectoryInfo(std::string root_path, std::string tep_resource_path, std::string shared_data_path, std::string shared_resource_path, - std::string shared_trusted_path) + std::string shared_trusted_path, + std::string res_control_allowed_res_path, + std::string res_control_global_res_path) : root_path_(std::move(root_path)), data_path_(std::move(data_path)), cache_path_(std::move(cache_path)), @@ -152,7 +171,9 @@ DirectoryInfo::DirectoryInfo(std::string root_path, tep_resource_path_(std::move(tep_resource_path)), shared_data_path_(std::move(shared_data_path)), shared_resource_path_(std::move(shared_resource_path)), - shared_trusted_path_(std::move(shared_trusted_path)) { + shared_trusted_path_(std::move(shared_trusted_path)), + res_control_allowed_res_path_(std::move(res_control_allowed_res_path)), + res_control_global_res_path_(std::move(res_control_global_res_path)) { } const std::string& DirectoryInfo::GetRootPath() const { @@ -187,4 +208,12 @@ const std::string& DirectoryInfo::GetSharedTrustedPath() const { return shared_trusted_path_; } +const std::string& DirectoryInfo::GetResControlAllowedResPath() const { + return res_control_allowed_res_path_; +} + +const std::string& DirectoryInfo::GetResControlGlobalResPath() const { + return res_control_global_res_path_; +} + } // namespace aul diff --git a/aul/app_info/directory_info.hh b/aul/app_info/directory_info.hh index 6a39fc4..b5c7130 100644 --- a/aul/app_info/directory_info.hh +++ b/aul/app_info/directory_info.hh @@ -35,6 +35,8 @@ class DirectoryInfo { const std::string& GetSharedDataPath() const; const std::string& GetSharedResourcePath() const; const std::string& GetSharedTrustedPath() const; + const std::string& GetResControlAllowedResPath() const; + const std::string& GetResControlGlobalResPath() const; private: class Builder { @@ -47,6 +49,8 @@ class DirectoryInfo { Builder& SetSharedDataPath(std::string shared_data_path); Builder& SetSharedResourcePath(std::string shared_resource_path); Builder& SetSharedTrustedPath(std::string shared_trusted_path); + Builder& SetResControlAllowedPath(std::string res_control_allowed_res_path); + Builder& SetResControlGlobalPath(std::string res_control_global_res_path); operator DirectoryInfo*(); @@ -60,6 +64,8 @@ class DirectoryInfo { std::string shared_data_path_; std::string shared_resource_path_; std::string shared_trusted_path_; + std::string res_control_allowed_res_path_; + std::string res_control_global_res_path_; }; DirectoryInfo(std::string root_path, @@ -69,7 +75,9 @@ class DirectoryInfo { std::string tep_resource_path, std::string shared_data_path, std::string shared_resource_path, - std::string shared_trusted_path); + std::string shared_trusted_path, + std::string res_control_allowed_res_path, + std::string res_control_global_res_path); private: std::string root_path_; @@ -80,6 +88,8 @@ class DirectoryInfo { std::string shared_data_path_; std::string shared_resource_path_; std::string shared_trusted_path_; + std::string res_control_allowed_res_path_; + std::string res_control_global_res_path_; }; } // namespace aul diff --git a/include/aul.h b/include/aul.h index bbe7c24..ea54687 100644 --- a/include/aul.h +++ b/include/aul.h @@ -2004,6 +2004,16 @@ const char *aul_get_app_specific_path(void); /* * This API is only for Appfw internally. */ +int aul_get_app_res_control_allowed_resource_path(const char *res_type, char **path); + +/* + * This API is only for Appfw internally. + */ +int aul_get_app_res_control_global_resource_path(const char *res_type, char **path); + +/* + * This API is only for Appfw internally. + */ int aul_get_app_shared_data_path_by_appid(const char *app_id, char **path); /* diff --git a/src/aul_path.cc b/src/aul_path.cc index d42e4a3..c681d59 100644 --- a/src/aul_path.cc +++ b/src/aul_path.cc @@ -159,6 +159,56 @@ AUL_API const char* aul_get_app_specific_path(void) { return tzplatform_getenv(TZ_USER_APP); } +AUL_API int aul_get_app_res_control_allowed_resource_path(const char* res_type, + char** path) { + if (res_type == nullptr || path == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + auto* context = GetCurrentContext(); + if (context == nullptr) + return AUL_R_ERROR; + + std::string result = context->GetResControlAllowedResPath() + res_type + "/"; + + if (access(result.c_str(), F_OK) != 0) + return AUL_R_EREJECTED; + + *path = strdup(result.c_str()); + if (*path == nullptr) { + LOGE("Out of memory"); + return AUL_R_ENOMEM; + } + + return AUL_R_OK; +} + +AUL_API int aul_get_app_res_control_global_resource_path(const char* res_type, + char** path) { + if (res_type == nullptr || path == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + auto* context = GetCurrentContext(); + if (context == nullptr) + return AUL_R_ERROR; + + std::string result = context->GetResControlGlobalResPath() + res_type + "/"; + + if (access(result.c_str(), F_OK) != 0) + return AUL_R_EREJECTED; + + *path = strdup(result.c_str()); + if (*path == nullptr) { + LOGE("Out of memory"); + return AUL_R_ENOMEM; + } + + return AUL_R_OK; +} + AUL_API int aul_get_app_shared_data_path_by_appid(const char* appid, char** path) { if (path == nullptr)