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";
43 std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
44 tzplatform_set_user(uid);
45 std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
46 tzplatform_reset_user();
50 std::string GetPath(const std::string& path,
51 const std::string& dir_name) {
52 return path + "/" + dir_name;
57 DirectoryInfo::Builder& DirectoryInfo::Builder::SetRootPath(
58 std::string root_path) {
59 root_path_ = std::move(root_path);
63 DirectoryInfo::Builder& DirectoryInfo::Builder::SetDataPath(
64 std::string data_path) {
65 data_path_ = std::move(data_path);
69 DirectoryInfo::Builder& DirectoryInfo::Builder::SetCachePath(
70 std::string cache_path) {
71 cache_path_ = std::move(cache_path);
75 DirectoryInfo::Builder& DirectoryInfo::Builder::SetResourcePath(
76 std::string resource_path) {
77 resource_path_ = std::move(resource_path);
81 DirectoryInfo::Builder& DirectoryInfo::Builder::SetTepResourcePath(
82 std::string tep_resource_path) {
83 tep_resource_path_ = std::move(tep_resource_path);
87 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedDataPath(
88 std::string shared_data_path) {
89 shared_data_path_ = std::move(shared_data_path);
93 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedResourcePath(
94 std::string shared_resource_path) {
95 shared_resource_path_ = std::move(shared_resource_path);
99 DirectoryInfo::Builder& DirectoryInfo::Builder::SetSharedTrustedPath(
100 std::string shared_trusted_path) {
101 shared_trusted_path_ = std::move(shared_trusted_path);
105 DirectoryInfo::Builder::operator DirectoryInfo*() {
106 return new (std::nothrow) DirectoryInfo(std::move(root_path_),
107 std::move(data_path_), std::move(cache_path_),
108 std::move(resource_path_), std::move(tep_resource_path_),
109 std::move(shared_data_path_), std::move(shared_resource_path_),
110 std::move(shared_trusted_path_));
113 DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
115 std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
116 if (info.get() == nullptr)
119 std::string root_path = info->GetRootPath();
120 std::string rw_path = GetRWPath(info->GetPkgId(), uid);
121 return Builder().SetRootPath(info->GetRootPath())
122 .SetDataPath(GetPath(rw_path, kDataDir))
123 .SetCachePath(GetPath(rw_path, kCacheDir))
124 .SetResourcePath(GetPath(root_path, kResourceDir))
125 .SetTepResourcePath(GetPath(root_path, kTepResourceDir))
126 .SetSharedDataPath(GetPath(rw_path, kSharedDataDir))
127 .SetSharedResourcePath(GetPath(root_path, kSharedResourceDir))
128 .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir));
131 DirectoryInfo* DirectoryInfo::Get() {
132 char app_id[256] = { 0, };
133 int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
137 return Get(app_id, getuid());
140 DirectoryInfo::DirectoryInfo(std::string root_path,
141 std::string data_path,
142 std::string cache_path,
143 std::string resource_path,
144 std::string tep_resource_path,
145 std::string shared_data_path,
146 std::string shared_resource_path,
147 std::string shared_trusted_path)
148 : root_path_(std::move(root_path)),
149 data_path_(std::move(data_path)),
150 cache_path_(std::move(cache_path)),
151 resource_path_(std::move(resource_path)),
152 tep_resource_path_(std::move(tep_resource_path)),
153 shared_data_path_(std::move(shared_data_path)),
154 shared_resource_path_(std::move(shared_resource_path)),
155 shared_trusted_path_(std::move(shared_trusted_path)) {
158 const std::string& DirectoryInfo::GetRootPath() const {
162 const std::string& DirectoryInfo::GetDataPath() const {
166 const std::string& DirectoryInfo::GetCachePath() const {
170 const std::string& DirectoryInfo::GetResourcePath() const {
171 return resource_path_;
174 const std::string& DirectoryInfo::GetTepResourcePath() const {
175 return tep_resource_path_;
178 const std::string& DirectoryInfo::GetSharedDataPath() const {
179 return shared_data_path_;
182 const std::string& DirectoryInfo::GetSharedResourcePath() const {
183 return shared_resource_path_;
186 const std::string& DirectoryInfo::GetSharedTrustedPath() const {
187 return shared_trusted_path_;