Remove storage library dependency
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Feb 2024 03:07:39 +0000 (12:07 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Feb 2024 09:46:18 +0000 (18:46 +0900)
To remove loading capi-system-info library, this patch removes
a libstorage dependency.

Change-Id: Iae64e8373001b8638dde362f4c8739f370a3618c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
packaging/aul.spec
src/aul/CMakeLists.txt
src/aul/app_info/external_directory_info.cc
test/unit_tests/CMakeLists.txt

index 73d819416acb0aeb2eca758d46405dd862ba87c6..9da7ab42e2c9623e3045cc7ae3bc753acc302a58 100644 (file)
@@ -58,7 +58,6 @@ PKG_CHECK_MODULES(PARCEL_DEPS REQUIRED parcel)
 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)
index 7d4160adf48411c0bff04aea89e962bffd60d342..38a11dd9214c5dae4ea9f7e681c1ad9a83fb5fed 100644 (file)
@@ -33,12 +33,13 @@ BuildRequires:  pkgconfig(parcel)
 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
index c4e8f07ba72e82b26670fb8a2dd21e24a0e2952f..2d9de984ffde0eb882a67e1c180161ea312e0c60 100644 (file)
@@ -47,7 +47,6 @@ APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC
   LIBTZPLATFORM_CONFIG_DEPS
   PARCEL_DEPS
   PKGMGR_INFO_DEPS
-  STORAGE_DEPS
   TTRACE_DEPS
   UUID_DEPS
   VCONF_DEPS
index eb1fef95736f060e4c6a7d21bc107698296d208a..8ed7c5b01d3e52341850d595d79cb2d95dc65c01 100644 (file)
@@ -15,7 +15,7 @@
  *
  */
 
-#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/" +
index 5c15dfd53b61fe89652ae705fd0128ee356f4c3f..4b370b1ad5b773c05d8326b5b9e42c3838f65158 100644 (file)
@@ -26,7 +26,6 @@ APPLY_PKG_CONFIG(${TARGET_AUL_UNIT_TESTS} PUBLIC
   LIBXML_DEPS
   PARCEL_DEPS
   PKGMGR_INFO_DEPS
-  STORAGE_DEPS
   TTRACE_DEPS
   UUID_DEPS
   VCONF_DEPS