PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
PKG_CHECK_MODULES(SQLITE3_DEPS REQUIRED sqlite3)
-PKG_CHECK_MODULES(STORAGE_DEPS REQUIRED storage)
PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace)
PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(sqlite3)
-BuildRequires: pkgconfig(storage)
BuildRequires: pkgconfig(ttrace)
BuildRequires: pkgconfig(uuid)
BuildRequires: pkgconfig(vconf)
BuildRequires: xdgmime-devel, pkgconfig(xdgmime)
+Requires: storage
+
%if 0%{?gcov:1}
BuildRequires: lcov
%endif
*
*/
-#include <storage-internal.h>
+#include <dlfcn.h>
#include <sys/types.h>
#include <tzplatform_config.h>
#include <unistd.h>
namespace aul {
namespace {
+constexpr const char kPathLibStorage[] = "/usr/lib/libstorage.so.0.1";
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);
-}
+class Storage {
+ public:
+ Storage() {
+ handle_ = dlopen(kPathLibStorage, RTLD_LAZY | RTLD_LOCAL);
+ if (handle_ == nullptr)
+ _E("dlopen() is failed. error(%s)", dlerror());
+ }
+
+ ~Storage() {
+ if (handle_) dlclose(handle_);
+ }
+
+ std::string GetPrimarySdcard() {
+ if (handle_ == nullptr) return {};
+
+ int (*storage_get_primary_sdcard_func)(int*, char**) =
+ reinterpret_cast<int (*)(int*, char**)>(
+ dlsym(handle_, "storage_get_primary_sdcard"));
+ if (storage_get_primary_sdcard_func == nullptr) {
+ _E("dlsym() is failed");
+ return {};
+ }
+
+ int storage_id = 0;
+ char* path = nullptr;
+ int ret = storage_get_primary_sdcard_func(&storage_id, &path);
+ if (ret != 0)
+ _E("storage_get_primary_sdcard() is failed. error(%d)", ret);
+
+ auto path_auto = std::unique_ptr<char, decltype(std::free)*>(path, free);
+ if (path) return std::string(path);
+
+ return std::string(kDefaultExternalStorage);
+ }
+
+ private:
+ void* handle_;
+};
std::string GetExternalPath(const std::string& pkg_id, uid_t uid) {
- std::string sdcard_path = GetSdCardPath();
+ Storage storage;
+ std::string sdcard_path = storage.GetPrimarySdcard();
tzplatform_set_user(uid);
std::string path = sdcard_path + "/apps/" +
std::string(tzplatform_getenv(TZ_USER_NAME)) + "/apps_rw/" +