Remove storage library dependency 52/305552/2
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 04:10:29 +0000 (13:10 +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 73d8194..9da7ab4 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 00f1d4b..8303c93 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 c4e8f07..2d9de98 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 eb1fef9..8ed7c5b 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 5c15dfd..4b370b1 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