[Systeminfo] Added handling Storage for TV profile in Systeminfo
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 7 Jan 2016 07:31:33 +0000 (08:31 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 13 Jan 2016 08:42:53 +0000 (09:42 +0100)
[Feature] Added two implementations of signal handling. Active one could be switched by define.
  1. was based on implementation from tizen_2.4_tv_product_migration branch
  2. was based on web wiki: https://wiki.tizen.org/wiki/System:Deviced#Usb_host specification

  On binary: 20160107.4, implementation based on Usb_host interface is correct and was tested and works correctly.
  Implementation 1 (based on tizen_2.4_tv_product_migration) seems to work in case of gathering storages also.

[Verification]
  On TV target 20160107.3 tct passrate:
  Archive 100%
  Content 100%
  Download 100%
  Systeminfo 100%
  Filesystem 100%.

  On TM1 device tct passrate:
  Archive 100%
  Content 100%
  Filesystem 100%
  Notification 100%
  Systeminfo 100%
  Systemsetting 96.97% (1 fail - SystemSettingManager_setProperty_errorCallback_invoked - binary issue)

Change-Id: I645119ecf949c4290f5307e74a5dcc0ee57e4d6f
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/common/common.gypi
src/common/filesystem/filesystem_provider_deviced.cc
src/common/filesystem/filesystem_provider_deviced.h
src/systeminfo/systeminfo_properties_manager.cc

index 0bf14e16b798333993681be57f947a6f9db923cc..0e15003a3431c16e8014fe6041ff6ff292082bfb 100644 (file)
@@ -37,7 +37,7 @@
         'sources/': [['exclude', '_tizen\\.cc$|tizen/']],
         'includes/': [['exclude', '_tizen\\.gypi$|tizen/']],
       }],
-      ['extension_host_os == "tv"', { 'defines': ['TIZEN_TV'] } ],
+      ['extension_host_os == "tv"', { 'defines': ['TIZEN_TV', 'USBHOST'] } ],
       ['extension_host_os == "wearable"', { 'defines': ['TIZEN_WEARABLE'] } ],
       ['extension_host_os == "mobile"', { 'defines': ['TIZEN_MOBILE'] } ],
       ['extension_host_os == "ivi"', { 'defines': ['TIZEN_IVI'] } ],
index ac08abc1e79f383f5622a72cf1a9e4e35b1122a1..e401376455c391b247c570ea92943dab199554c1 100644 (file)
 #include "common/logger.h"
 
 namespace {
+static const char* kDeviceDName = "org.tizen.system.deviced";
+#ifdef USBHOST
+static const char* kIface = "org.tizen.system.deviced.Usbhost";
+static const char* kPath = "/Org/Tizen/System/DeviceD/Usbhost";
+#else
 static const char* kIface = "org.tizen.system.deviced.BlockManager";
 static const char* kPath = "/Org/Tizen/System/DeviceD/Block/Manager";
+#endif
 }  // namespace
 
 namespace common {
@@ -61,6 +67,29 @@ struct DeviceListElem {
     bool primary;
 };
 
+struct UsbListElem {
+  UsbListElem()
+  : usb_devpath(nullptr),
+    usb_class(0),
+    usb_subclass(0),
+    usb_protocol(0),
+    usb_vendor_id(0),
+    usb_product_id(0),
+    usb_manufacturer(nullptr),
+    usb_product_name(nullptr),
+    usb_serial(nullptr) {}
+
+  char* usb_devpath;
+  int usb_class;
+  int usb_subclass;
+  int usb_protocol;
+  int usb_vendor_id;
+  int usb_product_id;
+  char* usb_manufacturer;
+  char* usb_product_name;
+  char* usb_serial;
+};
+
 FilesystemProviderDeviced::~FilesystemProviderDeviced() {
   LoggerD("Entered");
   UnregisterDeviceChangeState();
@@ -85,9 +114,8 @@ FilesystemProviderDeviced::FilesystemProviderDeviced() :
       LoggerE("Dbus handle is null");
     } else {
       LoggerE("Dbus connection set");
-      const gchar* unique_name = g_dbus_connection_get_unique_name(dbus_);
       proxy_ = g_dbus_proxy_new_sync(dbus_, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
-                                     nullptr, unique_name, kPath, kIface, nullptr,
+                                     nullptr, kDeviceDName, kPath, kIface, nullptr,
                                      &error);
       if (!proxy_ || error) {
         LoggerE("Could not get dbus proxy. %s", error->message);
@@ -183,6 +211,22 @@ std::shared_ptr<Storage> FilesystemProviderDeviced::GetStorage(const DeviceListE
                  elem.syspath, GetNameFromPath(elem.devnode)));
 }
 
+std::shared_ptr<Storage> FilesystemProviderDeviced::GetStorageUsb(const UsbListElem& elem) {
+  LoggerD("Entered");
+  SLoggerD("usb_devpath %s", elem.usb_devpath);
+  SLoggerD("usb_class %d", elem.usb_class);
+  SLoggerD("usb_subclass %d", elem.usb_subclass);
+  SLoggerD("usb_protocol %d", elem.usb_protocol);
+  SLoggerD("usb_vendor_id %d", elem.usb_vendor_id);
+  SLoggerD("usb_product_id %d", elem.usb_product_id);
+  SLoggerD("usb_manufacturer %s", elem.usb_manufacturer);
+  SLoggerD("usb_product_name %s", elem.usb_product_name);
+  SLoggerD("usb_serial %s", elem.usb_serial);
+  return std::make_shared<Storage>(Storage(elem.usb_product_id, StorageType::kExternal,
+                 StorageState::kMounted, // TODO: check if found storage is always mounted
+                 elem.usb_devpath, GetNameFromPath(elem.usb_devpath)));
+}
+
 std::string FilesystemProviderDeviced::GetNameFromPath(
     const char* const char_path) {
   LoggerD("Entered");
@@ -215,9 +259,15 @@ Storages FilesystemProviderDeviced::GetStorages() {
   }
 
   GError* error = nullptr;
+#ifdef USBHOST
+  GVariant* variant = g_dbus_proxy_call_sync(
+      proxy_, "GetDeviceList", g_variant_new("(i)", "0xffffffff"),
+      G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error);
+#else
   GVariant* variant = g_dbus_proxy_call_sync(
       proxy_, "GetDeviceList", g_variant_new("(s)", "all"),
       G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error);
+#endif
   if (!variant || error) {
     LoggerE("Failed to call GetDeviceList method - %s", error->message);
     return Storages();
@@ -228,18 +278,36 @@ Storages FilesystemProviderDeviced::GetStorages() {
 
 Storages FilesystemProviderDeviced::GetStoragesFromGVariant(GVariant* variant) {
   LoggerD("Entered");
+  SLoggerD("Imput variant looks like:\ng_variant_print(variant): %s", g_variant_print (variant, TRUE));
   Storages storages;
-  GVariantIter iter;
-  GVariant* tuple = nullptr;
-  g_variant_iter_init(&iter, variant);
-  while ((tuple = g_variant_iter_next_value(&iter))) {
-    DeviceListElem elem;
-    g_variant_get(tuple, "(issssssisib)", &elem.block_type, &elem.devnode,
-                  &elem.syspath, &elem.fs_usage, &elem.fs_type,
-                  &elem.fs_version, &elem.fs_uuid_enc, &elem.readonly,
-                  &elem.mount_point, &elem.state, &elem.primary);
-    storages.push_back(GetStorage(elem));
-    g_variant_unref(tuple);
+  GVariantIter iter_variant;
+  GVariant* array = nullptr;
+  g_variant_iter_init(&iter_variant, variant);
+  while ((array = g_variant_iter_next_value(&iter_variant))) {
+    GVariantIter iter_array;
+    g_variant_iter_init (&iter_array, array);
+    GVariant* array_elem = nullptr;
+
+    while ((array_elem = g_variant_iter_next_value (&iter_array))) {
+      SLoggerD("Adding storage: g_variant_print(array_elem): %s", g_variant_print (array_elem, TRUE));
+#ifdef USBHOST
+      UsbListElem elem;
+      g_variant_get(array_elem, "(siiiiisss)", &elem.usb_devpath, &elem.usb_class,
+                        &elem.usb_subclass, &elem.usb_protocol, &elem.usb_vendor_id,
+                        &elem.usb_product_id, &elem.usb_manufacturer, &elem.usb_product_name,
+                        &elem.usb_serial);
+      storages.push_back(GetStorageUsb(elem));
+#else
+      DeviceListElem elem;
+      g_variant_get(array_elem, "(issssssisib)", &elem.block_type, &elem.devnode,
+                    &elem.syspath, &elem.fs_usage, &elem.fs_type,
+                    &elem.fs_version, &elem.fs_uuid_enc, &elem.readonly,
+                    &elem.mount_point, &elem.state, &elem.primary);
+      storages.push_back(GetStorage(elem));
+#endif
+      g_variant_unref(array_elem);
+    }
+    g_variant_unref(array);
   }
   return storages;
 }
index c3094454518d75e47f05548621febb60cde46867..bae0ea5b6ba2704e011e489a93065463475e319b 100644 (file)
@@ -33,6 +33,7 @@
 namespace common {
 
 struct DeviceListElem;
+struct UsbListElem;
 
 class FilesystemProviderDeviced : public IFilesystemProvider {
  public:
@@ -59,6 +60,7 @@ class FilesystemProviderDeviced : public IFilesystemProvider {
   static std::string GetNameFromPath(const char* const char_path);
   static int GetIdFromUUID(const char* const char_uuid);
   static std::shared_ptr<Storage> GetStorage(const DeviceListElem& elem);
+  static std::shared_ptr<Storage> GetStorageUsb(const UsbListElem& elem);
   static Storages GetStoragesFromGVariant(GVariant* variant);
   GDBusConnection* dbus_;
   GDBusProxy* proxy_;
index 79c4c7ff1f3930829c99f1abad3840cede171214..1c34245836dd4e272d3b42358b7de07a2c1ec491 100644 (file)
@@ -31,6 +31,7 @@
 #include "systeminfo/systeminfo_device_capability.h"
 #include "common/scope_exit.h"
 #include "systeminfo/systeminfo-utils.h"
+#include "common/filesystem/filesystem_provider.h"
 
 namespace extension {
 namespace systeminfo {
@@ -60,6 +61,7 @@ const std::string kStorageSdcardPath = std::string(tzplatform_getenv(TZ_SYS_STOR
 const std::string kPropertyIdStorage = "STORAGE";
 const std::string kTypeUnknown = "UNKNOWN";
 const std::string kTypeInternal = "INTERNAL";
+const std::string kTypeUsbDevice = "USB_DEVICE";
 const std::string kTypeUsbHost = "USB_HOST";
 const std::string kTypeMmc = "MMC";
 //Network
@@ -1174,6 +1176,47 @@ static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojs
   out->insert(std::make_pair("isRemovable", picojson::value(isRemovable)));
 }
 
+#ifdef TIZEN_TV
+PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) {
+  LoggerD("Enter");
+
+  picojson::value result = picojson::value(picojson::array());
+  picojson::array& array = result.get<picojson::array>();
+
+  struct statfs fs;
+
+  // handling internal storage
+  array.push_back(picojson::value(picojson::object()));
+  picojson::object& internal_obj = array.back().get<picojson::object>();
+  if (statfs(kStorageInternalPath.c_str(), &fs) < 0) {
+    return LogAndCreateResult(
+              ErrorCode::UNKNOWN_ERR, "There are no storage units detected");
+  }
+  CreateStorageInfo(kTypeInternal, fs, &internal_obj);
+  manager_.SetAvailableCapacityInternal(fs.f_bavail);
+
+  // handling external storages
+  common::FilesystemProvider& provider(common::FilesystemProvider::Create());
+  auto storages = provider.GetStorages();
+  LoggerD("Storages found %d", storages.size());
+  for (auto storage : storages) {
+    if (storage->state() == common::StorageState::kMounted) {
+      if (statfs(storage->path().c_str(), &fs) < 0) {
+        LoggerE("Storage unit %s not detected", storage->name().c_str());
+        return PlatformResult(ErrorCode::UNKNOWN_ERR, "Storage unit not detected");
+      }
+      array.push_back(picojson::value(picojson::object()));
+      internal_obj = array.back().get<picojson::object>();
+      CreateStorageInfo(kTypeUsbDevice, fs, &internal_obj);
+      // TODO some tracking of available capacity of usb storages should be applied
+    }
+  }
+
+  out->insert(std::make_pair("storages", picojson::value(result)));
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+#else
+
 PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) {
   LoggerD("Entered");
   int sdcardState = 0;
@@ -1209,6 +1252,7 @@ PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out)
   out->insert(std::make_pair("storages", picojson::value(result)));
   return PlatformResult(ErrorCode::NO_ERROR);
 }
+#endif
 
 PlatformResult SysteminfoPropertiesManager::ReportCameraFlash(picojson::object* out,
                                                               unsigned long index) {