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_shared_data_path_by_appid(const char* appid,
167 if (appid == nullptr)
168 return aul_get_app_shared_data_path(path);
170 std::unique_ptr<aul::DirectoryInfo> info(
171 aul::DirectoryInfo::Get(appid, getuid()));
172 if (info.get() == nullptr)
175 if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
176 return AUL_R_EREJECTED;
178 *path = strdup(info->GetSharedDataPath().c_str());
182 AUL_API int aul_get_app_shared_resource_path_by_appid(const char* appid,
184 if (appid == nullptr || path == nullptr)
187 std::unique_ptr<aul::DirectoryInfo> info(
188 aul::DirectoryInfo::Get(appid, getuid()));
189 if (info.get() == nullptr)
192 *path = strdup(info->GetSharedResourcePath().c_str());
196 AUL_API int aul_get_app_shared_trusted_path_by_appid(const char* appid,
198 if (appid == nullptr || path == nullptr)
201 std::unique_ptr<aul::DirectoryInfo> info(
202 aul::DirectoryInfo::Get(appid, getuid()));
203 if (info.get() == nullptr)
206 *path = strdup(info->GetSharedTrustedPath().c_str());
210 AUL_API int aul_get_app_external_shared_data_path_by_appid(const char* appid,
212 if (appid == nullptr || path == nullptr)
215 std::unique_ptr<aul::ExternalDirectoryInfo> info(
216 aul::ExternalDirectoryInfo::Get(appid, getuid()));
217 if (info.get() == nullptr)
220 *path = strdup(info->GetSharedDataPath().c_str());
224 AUL_API int aul_get_usr_app_shared_data_path_by_appid(const char* appid,
225 char** path, uid_t uid) {
226 if (appid == nullptr || path == nullptr)
229 std::unique_ptr<aul::DirectoryInfo> info(
230 aul::DirectoryInfo::Get(appid, uid));
231 if (info.get() == nullptr)
234 if (access(info->GetSharedDataPath().c_str(), F_OK) != 0)
235 return AUL_R_EREJECTED;
237 *path = strdup(info->GetSharedDataPath().c_str());
241 AUL_API int aul_get_usr_app_shared_resource_path_by_appid(const char* appid,
242 char** path, uid_t uid) {
243 if (appid == nullptr || path == nullptr)
246 std::unique_ptr<aul::DirectoryInfo> info(
247 aul::DirectoryInfo::Get(appid, uid));
248 if (info.get() == nullptr)
251 *path = strdup(info->GetSharedResourcePath().c_str());
255 AUL_API int aul_get_usr_app_shared_trusted_path_by_appid(const char* appid,
256 char** path, uid_t uid) {
257 if (appid == nullptr || path == nullptr)
260 std::unique_ptr<aul::DirectoryInfo> info(
261 aul::DirectoryInfo::Get(appid, uid));
262 if (info.get() == nullptr)
265 *path = strdup(info->GetSharedTrustedPath().c_str());
269 AUL_API int aul_get_usr_app_external_shared_data_path_by_appid(
270 const char* appid, char** path, uid_t uid) {
271 if (appid == nullptr || path == nullptr)
274 std::unique_ptr<aul::ExternalDirectoryInfo> info(
275 aul::ExternalDirectoryInfo::Get(appid, uid));
276 if (info.get() == nullptr)
279 *path = strdup(info->GetSharedDataPath().c_str());