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.
22 #include "aul/app_info/directory_info.hh"
23 #include "aul/app_info/external_directory_info.hh"
26 #include "include/aul.h"
29 #define AUL_API extern "C" API
32 std::unique_ptr<aul::DirectoryInfo> context(nullptr);
33 std::unique_ptr<aul::ExternalDirectoryInfo> ext_context(nullptr);
37 const aul::DirectoryInfo* GetCurrentContext() {
38 std::unique_lock<std::mutex> lock(mutex);
39 if (context.get() == nullptr)
40 context.reset(aul::DirectoryInfo::Get());
45 const aul::ExternalDirectoryInfo* GetCurrentExtContext() {
46 std::unique_lock<std::mutex> lock(ext_mutex);
47 if (ext_context.get() == nullptr)
48 ext_context.reset(aul::ExternalDirectoryInfo::Get());
50 return ext_context.get();
55 AUL_API const char* aul_get_app_external_root_path(void) {
56 auto* context = GetCurrentExtContext();
57 if (context == nullptr)
60 return context->GetRootPath().c_str();
63 AUL_API const char* aul_get_app_root_path(void) {
64 auto* context = GetCurrentContext();
65 if (context == nullptr)
68 return context->GetRootPath().c_str();
71 AUL_API const char* aul_get_app_data_path(void) {
72 auto* context = GetCurrentContext();
73 if (context == nullptr)
76 return context->GetDataPath().c_str();
79 AUL_API const char* aul_get_app_cache_path(void) {
80 auto* context = GetCurrentContext();
81 if (context == nullptr)
84 return context->GetCachePath().c_str();
87 AUL_API const char* aul_get_app_resource_path(void) {
88 auto* context = GetCurrentContext();
89 if (context == nullptr)
92 return context->GetResourcePath().c_str();
95 AUL_API const char* aul_get_app_tep_resource_path(void) {
96 auto* context = GetCurrentContext();
97 if (context == nullptr)
100 return context->GetTepResourcePath().c_str();
103 AUL_API int aul_get_app_shared_data_path(char** path) {
104 auto* context = GetCurrentContext();
105 if (context == nullptr)
108 if (access(context->GetSharedDataPath().c_str(), F_OK) != 0)
109 return AUL_R_EREJECTED;
111 *path = strdup(context->GetSharedDataPath().c_str());
115 AUL_API const char* aul_get_app_shared_resource_path(void) {
116 auto* context = GetCurrentContext();
117 if (context == nullptr)
120 return context->GetSharedResourcePath().c_str();
123 AUL_API const char* aul_get_app_shared_trusted_path(void) {
124 auto* context = GetCurrentContext();
125 if (context == nullptr)
128 return context->GetSharedTrustedPath().c_str();
131 AUL_API const char* aul_get_app_external_data_path(void) {
132 auto* context = GetCurrentExtContext();
133 if (context == nullptr)
136 return context->GetDataPath().c_str();
139 AUL_API const char* aul_get_app_external_cache_path(void) {
140 auto* context = GetCurrentExtContext();
141 if (context == nullptr)
144 return context->GetCachePath().c_str();
147 AUL_API const char* aul_get_app_external_shared_data_path(void) {
148 auto* context = GetCurrentExtContext();
149 if (context == nullptr)
152 return context->GetSharedDataPath().c_str();
155 AUL_API const char* aul_get_app_specific_path(void) {
156 if (GetCurrentContext() == nullptr)
159 return tzplatform_getenv(TZ_USER_APP);
162 AUL_API int aul_get_app_res_control_allowed_resource_path(const char* res_type,
164 if (res_type == nullptr || path == nullptr) {
165 _E("Invalid parameter");
169 auto* context = GetCurrentContext();
170 if (context == nullptr)
173 std::string result = context->GetResControlAllowedResPath() + res_type + "/";
175 if (access(result.c_str(), F_OK) != 0)
176 return AUL_R_EREJECTED;
178 *path = strdup(result.c_str());
179 if (*path == nullptr) {
180 LOGE("Out of memory");
187 AUL_API int aul_get_app_res_control_global_resource_path(const char* res_type,
189 if (res_type == nullptr || path == nullptr) {
190 _E("Invalid parameter");
194 auto* context = GetCurrentContext();
195 if (context == nullptr)
198 std::string result = context->GetResControlGlobalResPath() + res_type + "/";
200 if (access(result.c_str(), F_OK) != 0)
201 return AUL_R_EREJECTED;
203 *path = strdup(result.c_str());
204 if (*path == nullptr) {
205 LOGE("Out of memory");
212 AUL_API int aul_get_app_shared_data_path_by_appid(const char* appid,
217 if (appid == nullptr)
218 return aul_get_app_shared_data_path(path);
220 std::unique_ptr<aul::DirectoryInfo> info(
221 aul::DirectoryInfo::Get(appid, getuid()));
222 if (info.get() == nullptr)
225 if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
226 return AUL_R_EREJECTED;
228 *path = strdup(info->GetSharedDataPath().c_str());
232 AUL_API int aul_get_app_shared_resource_path_by_appid(const char* appid,
234 if (appid == nullptr || path == nullptr)
237 std::unique_ptr<aul::DirectoryInfo> info(
238 aul::DirectoryInfo::Get(appid, getuid()));
239 if (info.get() == nullptr)
242 *path = strdup(info->GetSharedResourcePath().c_str());
246 AUL_API int aul_get_app_shared_trusted_path_by_appid(const char* appid,
248 if (appid == nullptr || path == nullptr)
251 std::unique_ptr<aul::DirectoryInfo> info(
252 aul::DirectoryInfo::Get(appid, getuid()));
253 if (info.get() == nullptr)
256 *path = strdup(info->GetSharedTrustedPath().c_str());
260 AUL_API int aul_get_app_external_shared_data_path_by_appid(const char* appid,
262 if (appid == nullptr || path == nullptr)
265 std::unique_ptr<aul::ExternalDirectoryInfo> info(
266 aul::ExternalDirectoryInfo::Get(appid, getuid()));
267 if (info.get() == nullptr)
270 *path = strdup(info->GetSharedDataPath().c_str());
274 AUL_API int aul_get_usr_app_shared_data_path_by_appid(const char* appid,
275 char** path, uid_t uid) {
276 if (appid == nullptr || path == nullptr)
279 std::unique_ptr<aul::DirectoryInfo> info(
280 aul::DirectoryInfo::Get(appid, uid));
281 if (info.get() == nullptr)
284 if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
285 return AUL_R_EREJECTED;
287 *path = strdup(info->GetSharedDataPath().c_str());
291 AUL_API int aul_get_usr_app_shared_resource_path_by_appid(const char* appid,
292 char** path, uid_t uid) {
293 if (appid == nullptr || path == nullptr)
296 std::unique_ptr<aul::DirectoryInfo> info(
297 aul::DirectoryInfo::Get(appid, uid));
298 if (info.get() == nullptr)
301 *path = strdup(info->GetSharedResourcePath().c_str());
305 AUL_API int aul_get_usr_app_shared_trusted_path_by_appid(const char* appid,
306 char** path, uid_t uid) {
307 if (appid == nullptr || path == nullptr)
310 std::unique_ptr<aul::DirectoryInfo> info(
311 aul::DirectoryInfo::Get(appid, uid));
312 if (info.get() == nullptr)
315 *path = strdup(info->GetSharedTrustedPath().c_str());
319 AUL_API int aul_get_usr_app_external_shared_data_path_by_appid(
320 const char* appid, char** path, uid_t uid) {
321 if (appid == nullptr || path == nullptr)
324 std::unique_ptr<aul::ExternalDirectoryInfo> info(
325 aul::ExternalDirectoryInfo::Get(appid, uid));
326 if (info.get() == nullptr)
329 *path = strdup(info->GetSharedDataPath().c_str());