2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/types.h>
19 #include <tzplatform_config.h>
24 #include "aul/app_info/app_info.hh"
25 #include "aul/app_info/directory_info.hh"
26 #include "aul/common/common.hh"
27 #include "aul/common/log_private.hh"
28 #include "include/aul.h"
33 constexpr const char kDataDir[] = "data/";
34 constexpr const char kCacheDir[] = "cache/";
35 constexpr const char kResourceDir[] = "res/";
36 constexpr const char kTepResourceDir[] = "tep/mount/";
37 constexpr const char kSharedDataDir[] = "shared/data/";
38 constexpr const char kSharedTrustedDir[] = "shared/trusted/";
39 constexpr const char kSharedResourceDir[] = "shared/res/";
40 constexpr const char kAppRWDir[] = "apps_rw/";
41 constexpr const char kLightUserSwitchModeDefault[] = "default";
42 constexpr const char kResControlAllowedDir[] = "res/mount/allowed/";
43 constexpr const char kResControlGlobalDir[] = "res/mount/global/";
45 std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
46 tzplatform_set_user(uid);
47 std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
48 tzplatform_reset_user();
52 std::string GetPath(const std::string& path,
53 const std::string& dir_name) {
54 return path + "/" + dir_name;
59 DirectoryInfo::Builder& DirectoryInfo::Builder::SetRootPath(
60 std::string root_path) {
61 root_path_ = std::move(root_path);
65 DirectoryInfo::Builder& DirectoryInfo::Builder::SetDataPath(
66 std::string data_path) {
67 data_path_ = std::move(data_path);
71 DirectoryInfo::Builder& DirectoryInfo::Builder::SetCachePath(
72 std::string cache_path) {
73 cache_path_ = std::move(cache_path);
77 DirectoryInfo::Builder& DirectoryInfo::Builder::SetResourcePath(
78 std::string resource_path) {
79 resource_path_ = std::move(resource_path);
83 DirectoryInfo::Builder& DirectoryInfo::Builder::SetTepResourcePath(
84 std::string tep_resource_path) {
85 tep_resource_path_ = std::move(tep_resource_path);
89 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedDataPath(
90 std::string shared_data_path) {
91 shared_data_path_ = std::move(shared_data_path);
95 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedResourcePath(
96 std::string shared_resource_path) {
97 shared_resource_path_ = std::move(shared_resource_path);
101 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedTrustedPath(
102 std::string shared_trusted_path) {
103 shared_trusted_path_ = std::move(shared_trusted_path);
107 DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlAllowedPath(
108 std::string res_control_allowed_res_path) {
109 res_control_allowed_res_path_ = std::move(res_control_allowed_res_path);
113 DirectoryInfo::Builder& DirectoryInfo::Builder::SetResControlGlobalPath(
114 std::string res_control_global_res_path) {
115 res_control_global_res_path_ = std::move(res_control_global_res_path);
119 DirectoryInfo::Builder::operator DirectoryInfo*() {
120 return new (std::nothrow) DirectoryInfo(std::move(root_path_),
121 std::move(data_path_), std::move(cache_path_),
122 std::move(resource_path_), std::move(tep_resource_path_),
123 std::move(shared_data_path_), std::move(shared_resource_path_),
124 std::move(shared_trusted_path_), std::move(res_control_allowed_res_path_),
125 std::move(res_control_global_res_path_));
128 DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
130 std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
131 if (info.get() == nullptr)
134 std::string root_path = info->GetRootPath();
135 std::string rw_path = GetRWPath(info->GetPkgId(), uid);
136 return Builder().SetRootPath(info->GetRootPath())
137 .SetDataPath(GetPath(rw_path, kDataDir))
138 .SetCachePath(GetPath(rw_path, kCacheDir))
139 .SetResourcePath(GetPath(root_path, kResourceDir))
140 .SetTepResourcePath(GetPath(root_path, kTepResourceDir))
141 .SetSharedDataPath(GetPath(rw_path, kSharedDataDir))
142 .SetSharedResourcePath(GetPath(root_path, kSharedResourceDir))
143 .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir))
144 .SetResControlAllowedPath(GetPath(root_path, kResControlAllowedDir))
145 .SetResControlGlobalPath(GetPath(root_path, kResControlGlobalDir));
148 DirectoryInfo* DirectoryInfo::Get() {
149 char app_id[256] = { 0, };
150 int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
154 return Get(app_id, getuid());
157 DirectoryInfo::DirectoryInfo(std::string root_path,
158 std::string data_path,
159 std::string cache_path,
160 std::string resource_path,
161 std::string tep_resource_path,
162 std::string shared_data_path,
163 std::string shared_resource_path,
164 std::string shared_trusted_path,
165 std::string res_control_allowed_res_path,
166 std::string res_control_global_res_path)
167 : root_path_(std::move(root_path)),
168 data_path_(std::move(data_path)),
169 cache_path_(std::move(cache_path)),
170 resource_path_(std::move(resource_path)),
171 tep_resource_path_(std::move(tep_resource_path)),
172 shared_data_path_(std::move(shared_data_path)),
173 shared_resource_path_(std::move(shared_resource_path)),
174 shared_trusted_path_(std::move(shared_trusted_path)),
175 res_control_allowed_res_path_(std::move(res_control_allowed_res_path)),
176 res_control_global_res_path_(std::move(res_control_global_res_path)) {
179 const std::string& DirectoryInfo::GetRootPath() const {
183 const std::string& DirectoryInfo::GetDataPath() const {
187 const std::string& DirectoryInfo::GetCachePath() const {
191 const std::string& DirectoryInfo::GetResourcePath() const {
192 return resource_path_;
195 const std::string& DirectoryInfo::GetTepResourcePath() const {
196 return tep_resource_path_;
199 const std::string& DirectoryInfo::GetSharedDataPath() const {
200 return shared_data_path_;
203 const std::string& DirectoryInfo::GetSharedResourcePath() const {
204 return shared_resource_path_;
207 const std::string& DirectoryInfo::GetSharedTrustedPath() const {
208 return shared_trusted_path_;
211 const std::string& DirectoryInfo::GetResControlAllowedResPath() const {
212 return res_control_allowed_res_path_;
215 const std::string& DirectoryInfo::GetResControlGlobalResPath() const {
216 return res_control_global_res_path_;