From: Piotr Kosko
Date: Thu, 11 Oct 2018 12:39:17 +0000 (+0200)
Subject: [Systeminfo] Internal implementation changed to use only public native API
X-Git-Tag: submit/tizen/20181023.123309~1^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6725b8dbde6261fcb9c86744bac83c1018924d2d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Systeminfo] Internal implementation changed to use only public native API
[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
---
diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp
index 88822809..a7e9c43a 100644
--- a/src/systeminfo/systeminfo-utils.cpp
+++ b/src/systeminfo/systeminfo-utils.cpp
@@ -19,8 +19,8 @@
#include
-#include
#include
+#include
#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(value) * MEMORY_TO_BYTE;
+ *result = static_cast(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(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(info.total - info.used) * MEMORY_TO_BYTE;
+
return PlatformResult(ErrorCode::NO_ERROR);
}
diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp
index 5822c008..221e477a 100644
--- a/src/systeminfo/systeminfo.gyp
+++ b/src/systeminfo/systeminfo.gyp
@@ -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',