*
*/
-#include <storage-internal.h>
#include <sys/types.h>
#include <tzplatform_config.h>
#include <unistd.h>
namespace aul {
namespace {
-constexpr const char kDefaultExternalStorage[] = "/opt/media/sdcard";
constexpr const char kDataDir[] = "data/";
constexpr const char kCacheDir[] = "cache/";
constexpr const char kResourceDir[] = "res/";
constexpr const char kSharedTrustedDir[] = "shared/trusted/";
constexpr const char kSharedResourceDir[] = "shared/res/";
-std::string GetSdCardPath() {
- int storage_id = 0;
- char* path = nullptr;
- int ret = storage_get_primary_sdcard(&storage_id, &path);
- if (ret != STORAGE_ERROR_NONE)
- _W("Failed to get primary sdcard. error(%d)", ret);
-
- auto ptr = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
- if (path)
- return std::string(path);
-
- return std::string(kDefaultExternalStorage);
-}
-
-std::string GetExternalPath(const std::string& pkg_id, uid_t uid) {
- std::string sdcard_path = GetSdCardPath();
- tzplatform_set_user(uid);
- std::string path = sdcard_path + "/apps/" +
- std::string(tzplatform_getenv(TZ_USER_NAME)) + "/apps_rw/" +
- pkg_id;
- tzplatform_reset_user();
- return path;
-}
-
std::string GetRWPath(const std::string& pkg_id, uid_t uid) {
tzplatform_set_user(uid);
std::string path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" + pkg_id;
return *this;
}
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetExternalRootPath(
- std::string external_root_path) {
- external_root_path_ = std::move(external_root_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetExternalDataPath(
- std::string external_data_path) {
- external_data_path_ = std::move(external_data_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetExternalCachePath(
- std::string external_cache_path) {
- external_cache_path_ = std::move(external_cache_path);
- return *this;
-}
-
-DirectoryInfo::Builder& DirectoryInfo::Builder::SetExternalSharedDataPath(
- std::string external_shared_data_path) {
- external_shared_data_path_ = std::move(external_shared_data_path);
- return *this;
-}
-
DirectoryInfo::Builder::operator DirectoryInfo*() const {
return new (std::nothrow) DirectoryInfo(root_path_, data_path_, cache_path_,
resource_path_, tep_resource_path_, shared_data_path_,
- shared_resource_path_, shared_trusted_path_, external_root_path_,
- external_data_path_, external_cache_path_, external_shared_data_path_);
+ shared_resource_path_, shared_trusted_path_);
}
DirectoryInfo* DirectoryInfo::Get(const std::string app_id,
std::string root_path = info->GetRootPath();
std::string rw_path = GetRWPath(info->GetPkgId(), uid);
- std::string external_path = GetExternalPath(info->GetPkgId(), uid);
return Builder().SetRootPath(info->GetRootPath())
.SetDataPath(GetPath(rw_path, kDataDir))
.SetCachePath(GetPath(rw_path, kCacheDir))
.SetTepResourcePath(GetPath(root_path, kTepResourceDir))
.SetSharedDataPath(GetPath(rw_path, kSharedDataDir))
.SetSharedResourcePath(GetPath(root_path, kSharedResourceDir))
- .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir))
- .SetExternalRootPath(std::string(external_path) + "/")
- .SetExternalDataPath(GetPath(external_path, kDataDir))
- .SetExternalCachePath(GetPath(external_path, kCacheDir))
- .SetExternalSharedDataPath(GetPath(external_path, kSharedDataDir));
+ .SetSharedTrustedPath(GetPath(rw_path, kSharedTrustedDir));
}
DirectoryInfo* DirectoryInfo::Get() {
std::string tep_resource_path,
std::string shared_data_path,
std::string shared_resource_path,
- std::string shared_trusted_path,
- std::string external_root_path,
- std::string external_data_path,
- std::string external_cache_path,
- std::string external_shared_data_path)
+ std::string shared_trusted_path)
: root_path_(std::move(root_path)),
data_path_(std::move(data_path)),
cache_path_(std::move(cache_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)),
- external_root_path_(std::move(external_root_path)),
- external_data_path_(std::move(external_data_path)),
- external_cache_path_(std::move(external_cache_path)),
- external_shared_data_path_(std::move(external_shared_data_path)) {
+ shared_trusted_path_(std::move(shared_trusted_path)) {
}
const std::string& DirectoryInfo::GetRootPath() const {
return shared_trusted_path_;
}
-const std::string& DirectoryInfo::GetExternalRootPath() const {
- return external_root_path_;
-}
-
-const std::string& DirectoryInfo::GetExternalDataPath() const {
- return external_data_path_;
-}
-
-const std::string& DirectoryInfo::GetExternalCachePath() const {
- return external_cache_path_;
-}
-
-const std::string& DirectoryInfo::GetExternalSharedDataPath() const {
- return external_shared_data_path_;
-}
-
} // namespace aul
class DirectoryInfo {
public:
+ static DirectoryInfo* Get(const std::string app_id, uid_t uid);
+ static DirectoryInfo* Get();
+
+ const std::string& GetRootPath() const;
+ const std::string& GetDataPath() const;
+ const std::string& GetCachePath() const;
+ const std::string& GetResourcePath() const;
+ const std::string& GetTepResourcePath() const;
+ const std::string& GetSharedDataPath() const;
+ const std::string& GetSharedResourcePath() const;
+ const std::string& GetSharedTrustedPath() const;
+
+ private:
class Builder {
public:
Builder& SetRootPath(std::string root_path);
Builder& SetSharedDataPath(std::string shared_data_path);
Builder& SetSharedResourcePath(std::string shared_resource_path);
Builder& SetSharedTrustedPath(std::string shared_trusted_path);
- Builder& SetExternalRootPath(std::string external_root_path);
- Builder& SetExternalDataPath(std::string external_data_path);
- Builder& SetExternalCachePath(std::string external_cache_path);
- Builder& SetExternalSharedDataPath(std::string external_shared_data_path);
operator DirectoryInfo*() const;
std::string shared_data_path_;
std::string shared_resource_path_;
std::string shared_trusted_path_;
- std::string external_root_path_;
- std::string external_data_path_;
- std::string external_cache_path_;
- std::string external_shared_data_path_;
};
- static DirectoryInfo* Get(const std::string app_id, uid_t uid);
- static DirectoryInfo* Get();
-
DirectoryInfo(std::string root_path,
std::string data_path,
std::string cache_path,
std::string tep_resource_path,
std::string shared_data_path,
std::string shared_resource_path,
- std::string shared_trusted_path,
- std::string external_root_path,
- std::string external_data_path,
- std::string external_cache_path,
- std::string external_shared_data_path);
-
- const std::string& GetRootPath() const;
- const std::string& GetDataPath() const;
- const std::string& GetCachePath() const;
- const std::string& GetResourcePath() const;
- const std::string& GetTepResourcePath() const;
- const std::string& GetSharedDataPath() const;
- const std::string& GetSharedResourcePath() const;
- const std::string& GetSharedTrustedPath() const;
- const std::string& GetExternalRootPath() const;
- const std::string& GetExternalDataPath() const;
- const std::string& GetExternalCachePath() const;
- const std::string& GetExternalSharedDataPath() const;
+ std::string shared_trusted_path);
private:
std::string root_path_;
std::string shared_data_path_;
std::string shared_resource_path_;
std::string shared_trusted_path_;
- std::string external_root_path_;
- std::string external_data_path_;
- std::string external_cache_path_;
- std::string external_shared_data_path_;
};
} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <storage-internal.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <memory>
+
+#include "aul/app_info/app_info.hh"
+#include "aul/app_info/external_directory_info.hh"
+#include "aul/common/common.hh"
+#include "aul/common/log_private.hh"
+#include "include/aul.h"
+
+namespace aul {
+namespace {
+
+constexpr const char kDefaultExternalStorage[] = "/opt/media/sdcard";
+constexpr const char kDataDir[] = "data/";
+constexpr const char kCacheDir[] = "cache/";
+constexpr const char kSharedDataDir[] = "shared/data/";
+
+std::string GetSdCardPath() {
+ int storage_id = 0;
+ char* path = nullptr;
+ int ret = storage_get_primary_sdcard(&storage_id, &path);
+ if (ret != STORAGE_ERROR_NONE)
+ _W("Failed to get primary sdcard. error(%d)", ret);
+
+ auto ptr = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
+ if (path)
+ return std::string(path);
+
+ return std::string(kDefaultExternalStorage);
+}
+
+std::string GetExternalPath(const std::string& pkg_id, uid_t uid) {
+ std::string sdcard_path = GetSdCardPath();
+ tzplatform_set_user(uid);
+ std::string path = sdcard_path + "/apps/" +
+ std::string(tzplatform_getenv(TZ_USER_NAME)) + "/apps_rw/" +
+ pkg_id;
+ tzplatform_reset_user();
+ return path;
+}
+
+std::string GetPath(const std::string& path,
+ const std::string& dir_name) {
+ return path + "/" + dir_name;
+}
+
+} // namespace
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetRootPath(
+ std::string root_path) {
+ root_path_ = std::move(root_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetDataPath(
+ std::string data_path) {
+ data_path_ = std::move(data_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder& ExternalDirectoryInfo::Builder::SetCachePath(
+ std::string cache_path) {
+ cache_path_ = std::move(cache_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder&
+ExternalDirectoryInfo::Builder::SetSharedDataPath(
+ std::string shared_data_path) {
+ shared_data_path_ = std::move(shared_data_path);
+ return *this;
+}
+
+ExternalDirectoryInfo::Builder::operator ExternalDirectoryInfo*() const {
+ return new (std::nothrow) ExternalDirectoryInfo(root_path_, data_path_,
+ cache_path_, shared_data_path_);
+}
+
+ExternalDirectoryInfo* ExternalDirectoryInfo::Get(const std::string app_id,
+ uid_t uid) {
+ std::unique_ptr<AppInfo> info(AppInfo::Get(app_id, uid));
+ if (info.get() == nullptr)
+ return nullptr;
+
+ std::string external_path = GetExternalPath(info->GetPkgId(), uid);
+ return Builder().SetRootPath(std::string(external_path) + "/")
+ .SetDataPath(GetPath(external_path, kDataDir))
+ .SetCachePath(GetPath(external_path, kCacheDir))
+ .SetSharedDataPath(GetPath(external_path, kSharedDataDir));
+}
+
+ExternalDirectoryInfo* ExternalDirectoryInfo::Get() {
+ char app_id[256] = { 0, };
+ int ret = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
+ if (ret != AUL_R_OK)
+ return nullptr;
+
+ return Get(app_id, getuid());
+}
+
+ExternalDirectoryInfo::ExternalDirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string shared_data_path)
+ : root_path_(std::move(root_path)),
+ data_path_(std::move(data_path)),
+ cache_path_(std::move(cache_path)),
+ shared_data_path_(std::move(shared_data_path)) {
+}
+
+const std::string& ExternalDirectoryInfo::GetRootPath() const {
+ return root_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetDataPath() const {
+ return data_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetCachePath() const {
+ return cache_path_;
+}
+
+const std::string& ExternalDirectoryInfo::GetSharedDataPath() const {
+ return shared_data_path_;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
+#define AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
+
+#include <string>
+
+namespace aul {
+
+class ExternalDirectoryInfo {
+ public:
+ static ExternalDirectoryInfo* Get(const std::string app_id, uid_t uid);
+ static ExternalDirectoryInfo* Get();
+
+ const std::string& GetRootPath() const;
+ const std::string& GetDataPath() const;
+ const std::string& GetCachePath() const;
+ const std::string& GetSharedDataPath() const;
+
+ private:
+ class Builder {
+ public:
+ Builder& SetRootPath(std::string root_path);
+ Builder& SetDataPath(std::string data_path);
+ Builder& SetCachePath(std::string cache_path);
+ Builder& SetSharedDataPath(std::string shared_data_path);
+
+ operator ExternalDirectoryInfo*() const;
+
+ private:
+ std::string root_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string shared_data_path_;
+ };
+
+ ExternalDirectoryInfo(std::string root_path,
+ std::string data_path,
+ std::string cache_path,
+ std::string shared_data_path);
+
+ private:
+ std::string root_path_;
+ std::string data_path_;
+ std::string cache_path_;
+ std::string shared_data_path_;
+};
+
+} // namespace aul
+
+#endif // AUL_APP_INFO_EXTERNAL_DIRECTORY_INFO_HH
#include <string>
#include "aul/app_info/directory_info.hh"
+#include "aul/app_info/external_directory_info.hh"
#include "aul_api.h"
#include "aul_util.h"
#include "include/aul.h"
namespace {
std::unique_ptr<aul::DirectoryInfo> context(nullptr);
+std::unique_ptr<aul::ExternalDirectoryInfo> ext_context(nullptr);
std::mutex mutex;
+std::mutex ext_mutex;
const aul::DirectoryInfo* GetCurrentContext() {
std::unique_lock<std::mutex> lock(mutex);
return context.get();
}
+const aul::ExternalDirectoryInfo* GetCurrentExtContext() {
+ std::unique_lock<std::mutex> lock(ext_mutex);
+ if (ext_context.get() == nullptr)
+ ext_context.reset(aul::ExternalDirectoryInfo::Get());
+
+ return ext_context.get();
+}
+
} // namespace
AUL_API const char* aul_get_app_external_root_path(void) {
- auto* context = GetCurrentContext();
+ auto* context = GetCurrentExtContext();
if (context == nullptr)
return nullptr;
- return context->GetExternalRootPath().c_str();
+ return context->GetRootPath().c_str();
}
AUL_API const char* aul_get_app_root_path(void) {
}
AUL_API const char* aul_get_app_external_data_path(void) {
- auto* context = GetCurrentContext();
+ auto* context = GetCurrentExtContext();
if (context == nullptr)
return nullptr;
- return context->GetExternalDataPath().c_str();
+ return context->GetDataPath().c_str();
}
AUL_API const char* aul_get_app_external_cache_path(void) {
- auto* context = GetCurrentContext();
+ auto* context = GetCurrentExtContext();
if (context == nullptr)
return nullptr;
- return context->GetExternalCachePath().c_str();
+ return context->GetCachePath().c_str();
}
AUL_API const char* aul_get_app_external_shared_data_path(void) {
- auto* context = GetCurrentContext();
+ auto* context = GetCurrentExtContext();
if (context == nullptr)
return nullptr;
- return context->GetExternalSharedDataPath().c_str();
+ return context->GetSharedDataPath().c_str();
}
AUL_API const char* aul_get_app_specific_path(void) {
if (appid == nullptr || path == nullptr)
return AUL_R_EINVAL;
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, getuid()));
+ std::unique_ptr<aul::ExternalDirectoryInfo> info(
+ aul::ExternalDirectoryInfo::Get(appid, getuid()));
if (info.get() == nullptr)
return AUL_R_ENOAPP;
- *path = strdup(info->GetExternalSharedDataPath().c_str());
+ *path = strdup(info->GetSharedDataPath().c_str());
return AUL_R_OK;
}
if (appid == nullptr || path == nullptr)
return AUL_R_EINVAL;
- std::unique_ptr<aul::DirectoryInfo> info(
- aul::DirectoryInfo::Get(appid, uid));
+ std::unique_ptr<aul::ExternalDirectoryInfo> info(
+ aul::ExternalDirectoryInfo::Get(appid, uid));
if (info.get() == nullptr)
return AUL_R_ENOAPP;
- *path = strdup(info->GetExternalSharedDataPath().c_str());
+ *path = strdup(info->GetSharedDataPath().c_str());
return AUL_R_OK;
}