[common] Check if external storage is supported. 02/216902/3
authorMichal Michalski <m.michalski2@partner.samsung.com>
Mon, 4 Nov 2019 16:19:47 +0000 (17:19 +0100)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 5 Nov 2019 09:18:22 +0000 (10:18 +0100)
If external.storage feature is not supported on the device,
we shouldn't try to fetch external storage devices list.

[Verification]
On mobile devices external storages are fetched.
On wearable devices only internal storages are returned.

+ tct-filesystem-tizen-tests 100% pass rate (mobile, wearable)

Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
Change-Id: I965c91c278ec85adbb81e7ca98b4b98604011b23

src/common/common.gyp
src/common/filesystem/filesystem_provider_deviced.cc

index 9f7729a..1baffe0 100644 (file)
@@ -71,6 +71,7 @@
               'capi-appfw-app-manager',
               'capi-appfw-app-common',
               'capi-appfw-package-manager',
+              'capi-system-info',
               'storage',
               'security-privilege-manager',
             ]
index cb33bd7..60bc109 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "common/filesystem/filesystem_provider_deviced.h"
+#include <system_info.h>
 
 #include <gio/gio.h>
 #include <algorithm>
 #include "common/logger.h"
 
 namespace {
+
 static const char* kBus = "org.tizen.system.storage";
 static const char* kBlockManagerIface = "org.tizen.system.storage.BlockManager";
 static const char* kPath = "/Org/Tizen/System/Storage/Block/Manager";
 static const char* kDeviceChangedMethod = "DeviceChanged";
 static const char* kGetDeviceListMethod = "GetDeviceList";
+static const char* kExternalStorageFeature = "http://tizen.org/feature/storage.external";
+
+bool isExternalStorageSupported() {
+  bool external_storage_support = false;
+  auto ret = system_info_get_platform_bool(kExternalStorageFeature, &external_storage_support);
+
+  if (SYSTEM_INFO_ERROR_NONE != ret) {
+    LoggerE("system_info_get_platform_bool(storage.external) check failed: %d (%s)", ret,
+            get_error_message(ret));
+    return false;
+  }
+
+  if (!external_storage_support) {
+    LoggerW("External storage not supported.");
+    return false;
+  }
+
+  return true;
+}
+
 }  // namespace
 
 namespace common {
@@ -221,10 +243,13 @@ Storages FilesystemProviderDeviced::GetStorages() {
     return Storages();
   }
 
-  // internal storages are gathered with storage api
   Storages internal = virtual_roots_provider_.GetStorages();
 
-  // external storages are gathered using deviced implementation
+  if (!isExternalStorageSupported()) {
+    return internal;
+  }
+
+  LoggerD("Fetching external storages.");
   Storages result;
   GError* error = nullptr;
   GVariant* variant = g_dbus_connection_call_sync(dbus_, kBus, kPath, kBlockManagerIface,
@@ -237,7 +262,6 @@ Storages FilesystemProviderDeviced::GetStorages() {
     LoggerD("GetDeviceList succeed - handling result");
     result = GetStoragesFromGVariant(variant);
   }
-
   // merging internal and external results together, but internal on the beginning
   result.insert(result.begin(), internal.begin(), internal.end());
   return result;