[Systeminfo] change statfs to storage_get_(internal/external)_memory_size 00/113600/2
authorLukasz Bardeli <l.bardeli@samsung.com>
Wed, 8 Feb 2017 07:56:47 +0000 (08:56 +0100)
committerLukasz Bardeli <l.bardeli@samsung.com>
Wed, 8 Feb 2017 07:56:47 +0000 (08:56 +0100)
[Verification] code compiles without error, TCT passrate 100%

Change-Id: I41e0b078d4005528b0a6e2db411357b0052fc580
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/systeminfo/systeminfo_properties_manager.cc

index 9d87daa1ed148d8d96c48540c16778b17a3e84ad..cfaa784123a147f44ba3c5d83094b2e17e25b11b 100644 (file)
@@ -25,7 +25,7 @@
 #include <system_settings.h>
 #include <net_connection.h>
 #include <tzplatform_config.h>
-#include <sys/statfs.h>
+#include <storage.h>
 
 #include "systeminfo/systeminfo_manager.h"
 #include "systeminfo/systeminfo_device_capability.h"
@@ -1156,14 +1156,14 @@ PlatformResult SysteminfoPropertiesManager::ReportMemory(picojson::object* out)
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) {
+static void CreateStorageInfo(const std::string& type, struct statvfs& fs, picojson::object* out) {
   LoggerD("Entered");
   out->insert(std::make_pair("type", picojson::value(type)));
   out->insert(std::make_pair("capacity", picojson::value(std::to_string(
-      static_cast<unsigned long long>(fs.f_bsize) *
+      static_cast<unsigned long long>(fs.f_frsize) *
       static_cast<unsigned long long>(fs.f_blocks)))));
   out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string(
-      static_cast<unsigned long long>(fs.f_bsize) *
+      static_cast<unsigned long long>(fs.f_frsize) *
       static_cast<unsigned long long>(fs.f_bavail)))));
   bool isRemovable = (type == kTypeInternal) ? false : true;
   out->insert(std::make_pair("isRemovable", picojson::value(isRemovable)));
@@ -1186,7 +1186,7 @@ static std::string FromStorageTypeToStringType(common::StorageType type) {
 
 PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) {
   LoggerD("Entered");
-  struct statfs fs;
+  struct statvfs fs;
 
   picojson::value result = picojson::value(picojson::array());
   picojson::array& array = result.get<picojson::array>();
@@ -1197,20 +1197,25 @@ PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out)
   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()));
-      picojson::object& external_obj = array.back().get<picojson::object>();
-      CreateStorageInfo(FromStorageTypeToStringType(storage->type()), fs, &external_obj);
-
       //TODO change implementation to support all types of storages and not limited number
       if (common::StorageType::kInternal == storage->type()) {
+        if (storage_get_internal_memory_size(&fs) < 0) {
+          LoggerE("Storage unit %s not detected", storage->name().c_str());
+          return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected");
+        }
         manager_.SetAvailableCapacityInternal(fs.f_bavail);
       } else if (common::StorageType::kMmc == storage->type()) {
+        if (storage_get_external_memory_size(&fs) < 0) {
+          LoggerE("Storage unit %s not detected", storage->name().c_str());
+          return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible");
+        }
         manager_.SetAvailableCapacityMmc(fs.f_bavail);
       }
+
+      array.push_back(picojson::value(picojson::object()));
+      picojson::object& external_obj = array.back().get<picojson::object>();
+      CreateStorageInfo(FromStorageTypeToStringType(storage->type()), fs, &external_obj);
+
     }
   }