[Systeminfo] Internal implementation changed to use only public native API 28/191128/3
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 11 Oct 2018 12:39:17 +0000 (14:39 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 15 Oct 2018 06:07:14 +0000 (08:07 +0200)
[Feature] The internal implementaiton was using non-public API of device.h
  library, which makes the hazard of not being supported in future versions.
  To avoid the risk of that, the implementation was improved to use only
  public API. Changed implementation has a guarantee that the API change
  is maintained properly and will not disappear (could be removed only following
  the deprecation and removal procedure).

[Verification] Methods getAvailableMemory() and getTotalMemory() were checked
  with Chrome console.
  TCT passrate of systeminfo module was not changed.

Change-Id: If6f651979f3b3010834f91ff6699b53c770ee760
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/systeminfo/systeminfo-utils.cpp
src/systeminfo/systeminfo.gyp

index 8882280..a7e9c43 100644 (file)
@@ -19,8 +19,8 @@
 
 #include <memory>
 
-#include <device.h>
 #include <net_connection.h>
+#include <runtime_info.h>
 
 #include "common/logger.h"
 #include "common/platform_exception.h"
@@ -121,17 +121,16 @@ PlatformResult SysteminfoUtils::CheckIfEthernetNetworkSupported() {
 PlatformResult SysteminfoUtils::GetTotalMemory(long long *result) {
   ScopeLogger();
 
-  unsigned int value = 0;
-
-  int ret = device_memory_get_total(&value);
-  if (ret != DEVICE_ERROR_NONE) {
-    std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+  runtime_memory_info_s info = {0};
+  int ret = runtime_info_get_system_memory_info(&info);
+  if (ret != RUNTIME_INFO_ERROR_NONE) {
+    std::string log_msg = "Failed to get system memory info: " + std::to_string(ret);
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, log_msg,
-        ("device_memory_get_total error: %d (%s)", ret, get_error_message(ret)));
+        ("runtime_info_get_system_memory_info error: %d (%s)", ret, get_error_message(ret)));
   }
 
-  *result = static_cast<long long>(value) * MEMORY_TO_BYTE;
+  *result = static_cast<long long>(info.total) * MEMORY_TO_BYTE;
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
@@ -139,17 +138,19 @@ PlatformResult SysteminfoUtils::GetTotalMemory(long long *result) {
 PlatformResult SysteminfoUtils::GetAvailableMemory(long long *result) {
   ScopeLogger();
 
-  unsigned int value = 0;
-
-  int ret = device_memory_get_available(&value);
-  if (ret != DEVICE_ERROR_NONE) {
-    std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+  runtime_memory_info_s info = {0};
+  int ret = runtime_info_get_system_memory_info(&info);
+  if (ret != RUNTIME_INFO_ERROR_NONE) {
+    std::string log_msg = "Failed to get system memory info: " + std::to_string(ret);
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, log_msg,
-        ("device_memory_get_available error: %d (%s)", ret, get_error_message(ret)));
+        ("runtime_info_get_system_memory_info error: %d (%s)", ret, get_error_message(ret)));
   }
 
-  *result = static_cast<long long>(value) * MEMORY_TO_BYTE;
+  // as the WebIDL says the available memory means "amount of memory that is not in use (in bytes)",
+  // the result value is evaluated exactly this way, basing on total and used memory.
+  *result = static_cast<long long>(info.total - info.used) * MEMORY_TO_BYTE;
+
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
index 5822c00..221e477 100644 (file)
@@ -38,7 +38,7 @@
             'glib-2.0',
             'capi-system-info',
             'capi-network-connection',
-            'capi-system-device',
+            'capi-system-runtime-info',
             'capi-system-system-settings',
             'capi-network-wifi-manager',
             'libtzplatform-config',