From 797bf22c8636937caf9e4f48187bb22591ff742d Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Thu, 13 Jul 2017 21:57:37 +0200
Subject: [PATCH 01/16] [Application] Fix category array population bug
Problem: application's categories were not passed from C++ to JS layer
Verification: it has been proved in tests in Chrome DevTools, that
application's categories may be obtained with Application API
TCT Application pass rate: 100%
Change-Id: I0995cd464315c9194196874fa488d52de49b1e69
Signed-off-by: Pawel Wasowski
---
src/application/application_utils.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/application/application_utils.cc b/src/application/application_utils.cc
index 8d56999..060dd09 100644
--- a/src/application/application_utils.cc
+++ b/src/application/application_utils.cc
@@ -77,7 +77,6 @@ void ApplicationUtils::CreateApplicationInformation(const pkgmgrinfo_appinfo_h h
// categories
picojson::value categories = picojson::value(picojson::array());
picojson::array& categories_array = categories.get();
- app_info->insert(std::make_pair("categories", categories));
ret = pkgmgrinfo_appinfo_foreach_category(
handle,
@@ -92,6 +91,8 @@ void ApplicationUtils::CreateApplicationInformation(const pkgmgrinfo_appinfo_h h
},
&categories_array);
+ app_info->insert(std::make_pair("categories", categories));
+
if (PMINFO_R_OK != ret) {
LoggerE("Failed to get categories: %d (%s)", ret, get_error_message(ret));
}
--
2.7.4
From 53b941ffca00a9cc12d3207280f179f16452cbba Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Fri, 7 Jul 2017 18:02:53 +0200
Subject: [PATCH 02/16] [EXIF] Fix privilege issue
Problem: implementation of getExifInfo() used Web API filesystem
resolve() function to check, if file exists on the device. Use of this
function required declaring http://tizen.org/privilege/filesystem.read.
File existence checking has been implemented in EXIF plugin and does not
require declaring any additional privileges.
[Verification] TCT EXIF: 100% pass rate,
manuall tests with Chrome DevTools did not show any problems
Change-Id: Id9d19965eddb31902f14817eac0bd5ad897f1568
Signed-off-by: Pawel Wasowski
---
src/common/tools.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++
src/common/tools.h | 6 ++++++
src/exif/exif_api.js | 21 ++----------------
src/exif/exif_instance.cc | 16 ++++++++++++++
4 files changed, 79 insertions(+), 19 deletions(-)
diff --git a/src/common/tools.cc b/src/common/tools.cc
index 638352f..cd8beea 100644
--- a/src/common/tools.cc
+++ b/src/common/tools.cc
@@ -19,6 +19,7 @@
#include
#include
#include
+#include
#ifdef PRIVILEGE_USE_DB
#include
@@ -480,5 +481,59 @@ char* BinToHex(const unsigned char* bin, int size, char* hex, int hex_size) {
return hex;
}
+bool IsPathValid(const std::string& path) {
+ LoggerD("Enter");
+
+ /*
+ * Directory dot-referencing is not allowed
+ */
+ return std::string::npos == path.find("/../") &&
+ std::string::npos == path.find("/./") &&
+ 0 != path.find("./") &&
+ 0 != path.find("../") &&
+ path.length() - 2 != path.rfind("/.") &&
+ path.length() - 3 != path.rfind("/..");
+}
+
+PlatformResult CheckFileStatus(const std::string& path) {
+ LoggerD("Enter");
+
+ struct stat buf;
+
+ if (stat(path.c_str(), &buf)) {
+ LoggerD("Failed to stat path: %s", path.c_str());
+
+ if (ENOENT == errno) {
+ return PlatformResult(ErrorCode::NOT_FOUND_ERR, "File does not exist: " + path);
+ } else if (EACCES == errno) {
+ return PlatformResult(ErrorCode::IO_ERR, "The user cannot access the file: " + path);
+ }
+
+ LoggerD("stat() error: %s", common::tools::GetErrorString(errno).c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get status of the file: " + path);
+ }
+
+ if (!S_ISREG(buf.st_mode)) {
+ return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Path does not point to a regular file: "
+ + path);
+ }
+
+ if (!(S_IRUSR & buf.st_mode)) {
+ return PlatformResult(ErrorCode::IO_ERR, "The user cannot read the file: " + path);
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CheckFileAvailability(const std::string& path) {
+ LoggerD("Enter");
+
+ if (!IsPathValid(path)) {
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid path: " + path);
+ }
+
+ return CheckFileStatus(path);
+}
+
} // namespace tools
} // namespace common
diff --git a/src/common/tools.h b/src/common/tools.h
index 5d8eec6..fc905ec 100644
--- a/src/common/tools.h
+++ b/src/common/tools.h
@@ -85,6 +85,12 @@ int HexToInt(char c);
unsigned char* HexToBin(const char* hex, int size, unsigned char* bin, int bin_size);
char* BinToHex(const unsigned char* bin, int size, char* hex, int hex_size);
+bool IsPathValid(const std::string& path);
+
+PlatformResult CheckFileStatus(const std::string& path);
+
+PlatformResult CheckFileAvailability(const std::string& path);
+
} // namespace tools
} // namespace common
diff --git a/src/exif/exif_api.js b/src/exif/exif_api.js
index d209d8a..3040336 100644
--- a/src/exif/exif_api.js
+++ b/src/exif/exif_api.js
@@ -205,7 +205,6 @@ ExifManager.prototype.getExifInfo = function() {
if (native_.isFailure(result)) {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
-
// call to c++ code. Fields that do not exist are undefined.
var exifInfoNative = native_.getResultObject(result);
@@ -218,15 +217,7 @@ ExifManager.prototype.getExifInfo = function() {
}
};
- tizen.filesystem.resolve(args.uri,
- function() {
- native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
- },
- function() {
- native_.callIfPossible(args.errorCallback, new WebAPIException(
- WebAPIException.NOT_FOUND_ERR,
- 'File can not be found.'));
- });
+ native_.call('ExifManager_getExifInfo', {'uri': args.uri}, callback);
};
ExifManager.prototype.saveExifInfo = function() {
@@ -316,15 +307,7 @@ ExifManager.prototype.getThumbnail = function() {
}
};
- tizen.filesystem.resolve(args.uri,
- function() {
- native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
- },
- function() {
- native_.callIfPossible(args.errorCallback, new WebAPIException(
- WebAPIException.NOT_FOUND_ERR,
- 'File can not be found.'));
- });
+ native_.call('ExifManager_getThumbnail', {'uri': args.uri}, _callback);
};
tizen.ExifInformation = function() {
diff --git a/src/exif/exif_instance.cc b/src/exif/exif_instance.cc
index 8be6a26..6f0101a 100755
--- a/src/exif/exif_instance.cc
+++ b/src/exif/exif_instance.cc
@@ -26,6 +26,7 @@
#include "common/logger.h"
#include "common/platform_result.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "exif/exif_information.h"
#include "exif/exif_util.h"
@@ -62,6 +63,13 @@ void ExifInstance::ExifManagerGetExifInfo(const picojson::value& args, picojson:
PlatformResult status(ErrorCode::NO_ERROR);
const std::string &file_path = ExifUtil::convertUriToPath(uri);
+
+ PlatformResult fileAvailability(common::tools::CheckFileAvailability(file_path));
+ if (!fileAvailability) {
+ LogAndReportError(fileAvailability, &response->get());
+ return;
+ }
+
LoggerD("file_path = %s", file_path.c_str());
status = GetExifInfo::LoadFromURI(uri, &result);
@@ -128,6 +136,14 @@ void ExifInstance::ExifManagerGetThumbnail(const picojson::value& args,
JsonValue result = JsonValue(JsonObject());
JsonObject &result_obj = result.get();
+ PlatformResult fileAvailability(common::tools::CheckFileAvailability(file_path));
+ if (!fileAvailability) {
+ LogAndReportError(fileAvailability, &response->get());
+ return;
+ }
+
+ LoggerD("file_path = %s", file_path.c_str());
+
std::string ext = file_path.substr(file_path.find_last_of(".") + 1);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
--
2.7.4
From 0c75237768f62a473b054feeb7c31c56c156f67f Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Tue, 18 Jul 2017 11:20:35 +0200
Subject: [PATCH 03/16] [Systeminfo] Fixed condition, which caused to call
successCallback when not needed
According to documentation, the successCallback is called in
4 different possible situations.
The condition, which fills the requirements is optimized.
[Verification] SystemInfo TCT passed 100%.
Change-Id: Ie6b24853ed233ecb8ac9d5ee28677e84d2b22f2f
Signed-off-by: Szymon Jastrzebski
---
src/systeminfo/systeminfo_api.js | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js
index bb656c0..63b3e5e 100644
--- a/src/systeminfo/systeminfo_api.js
+++ b/src/systeminfo/systeminfo_api.js
@@ -901,10 +901,20 @@ function _systeminfoBatteryListenerCallback(eventObj) {
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.level <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.level >= listener.highThreshold));
+ /*
+ * According to documentation, the condition should look like this:
+ *
+ * (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ * (!T_.isUndefined(listener.lowThreshold) && !T_.isUndefined(listener.highThreshold) && (propObj.level <= listener.lowThreshold || propObj.level >= listener.highThreshold)) ||
+ * (!T_.isUndefined(listener.lowThreshold) && (propObj.level <= listener.lowThreshold)) ||
+ * (!T_.isUndefined(listener.highThreshold) && (propObj.level >= listener.highThreshold))
+ *
+ * but it can be optimized like this:
+ */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.level <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.level >= listener.highThreshold);
+
if (executeCall) {
listener.callback(propObj);
}
@@ -922,10 +932,12 @@ function _systeminfoCpuListenerCallback(eventObj) {
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.load <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.load >= listener.highThreshold));
+ /*
+ * Optimized condition:
+ * */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.load <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.load >= listener.highThreshold);
if (executeCall) {
listener.callback(propObj);
}
@@ -958,10 +970,12 @@ function _systeminfoDisplayListenerCallback(eventObj) {
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
- var executeCall = (T_.isUndefined(listener.lowThreshold) ||
- (propObj.brightness <= listener.lowThreshold)) ||
- (T_.isUndefined(listener.highThreshold) ||
- (propObj.brightness >= listener.highThreshold));
+ /*
+ * Optimized condition:
+ * */
+ var executeCall = (T_.isUndefined(listener.lowThreshold) && T_.isUndefined(listener.highThreshold)) ||
+ (!T_.isUndefined(listener.lowThreshold) && propObj.brightness <= listener.lowThreshold) ||
+ (!T_.isUndefined(listener.highThreshold) && propObj.brightness >= listener.highThreshold);
if (executeCall) {
listener.callback(propObj);
}
--
2.7.4
From 14e60fd52a8e8c5e8b6b4aba5d4bd5c2a4859a96 Mon Sep 17 00:00:00 2001
From: Lukasz Bardeli
Date: Wed, 19 Jul 2017 08:39:23 +0200
Subject: [PATCH 04/16] [SystemInfo] adding support vfpv4
[Verification] Code compiles without error. TCT passrate 100%
Change-Id: Ibdca896ec76ca69b0269285c1eb735e4b10a1064
Signed-off-by: Lukasz Bardeli
---
src/systeminfo/systeminfo_device_capability.cc | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/systeminfo/systeminfo_device_capability.cc b/src/systeminfo/systeminfo_device_capability.cc
index cec92de..c1976d2 100644
--- a/src/systeminfo/systeminfo_device_capability.cc
+++ b/src/systeminfo/systeminfo_device_capability.cc
@@ -62,6 +62,7 @@ const char* kPlatformCoreSse3 = "sse3";
const char* kPlatformCoreSsse3 = "ssse3";
const char* kPlatformCoreVfpv2 = "vfpv2";
const char* kPlatformCoreVfpv3 = "vfpv3";
+const char* kPlatformCoreVfpv4 = "vfpv4";
/*API feature*/
/*Network feature*/
@@ -518,6 +519,17 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re
}
result += kPlatformCoreVfpv3;
}
+
+ ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv4", &bool_result);
+ if (ret.IsError()) {
+ return ret;
+ }
+ if (bool_result) {
+ if (!result.empty()) {
+ result += kPlatformCoreDelimiter;
+ }
+ result += kPlatformCoreVfpv4;
+ }
if (result.empty()) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "platformCoreFpuArch result is empty");
}
--
2.7.4
From 557cd7f81bb475633bdaa8147bdce701880d1674 Mon Sep 17 00:00:00 2001
From: Lukasz Bardeli
Date: Wed, 19 Jul 2017 09:07:36 +0200
Subject: [PATCH 05/16] [version] 1.91
Change-Id: I253cb2dfb07843f3a46694eba5a69719d6006450
---
packaging/webapi-plugins.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec
index 9d193c9..926b460 100644
--- a/packaging/webapi-plugins.spec
+++ b/packaging/webapi-plugins.spec
@@ -10,7 +10,7 @@
%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
Name: webapi-plugins
-Version: 1.90
+Version: 1.91
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From b5569c9d1f6a78a4c6279d20b6bcabdfce1999f8 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 19 Jul 2017 10:26:56 +0200
Subject: [PATCH 06/16] [Messaging] Adding checking return value of calloc
SVACE detected problem with code DEREF_OF_NULL.RET.ALLOC.
[Verification] Code compiles.
Change-Id: Ibf604637e9f9d08e8c486a421afd94bbe6d6bddc
Signed-off-by: Szymon Jastrzebski
---
src/messaging/message.cc | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/messaging/message.cc b/src/messaging/message.cc
index 57703b1..14f3763 100755
--- a/src/messaging/message.cc
+++ b/src/messaging/message.cc
@@ -592,6 +592,10 @@ PlatformResult addSingleEmailAttachment(std::shared_ptr message,
if (ret.IsError()) return ret;
email_attachment_data_t* tmp = (email_attachment_data_t*)calloc(1, sizeof(email_attachment_data_t));
+ if (nullptr == tmp) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error while adding attachment.");
+ }
tmp->attachment_name = strdup(att->getShortFileName().c_str());
tmp->attachment_path = strdup(std::string(dirPath + "/"
+ att->getShortFileName()).c_str());
--
2.7.4
From f0e83be2b496b74fa0dd5b8cc597a0b78141a360 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 19 Jul 2017 12:35:55 +0200
Subject: [PATCH 07/16] [SystemInfo] Adding casting int to double + fix
InchToMm constant
SVACE detected problem with code NO_CAST.INTEGER_DIVISION.
[Verification] Code compiles, TCT SystemInfo passed 100%.
Change-Id: Ie6249780860cd61a8c331d77648b6d37b9241c4c
Signed-off-by: Szymon Jastrzebski
---
src/systeminfo/systeminfo_properties_manager.cc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc
index 8a5c6e4..75bb33c 100644
--- a/src/systeminfo/systeminfo_properties_manager.cc
+++ b/src/systeminfo/systeminfo_properties_manager.cc
@@ -42,7 +42,7 @@ using common::ErrorCode;
namespace {
const std::string kMemoryStateNormal = "NORMAL";
const std::string kMemoryStateWarinig = "WARNING";
-const double kDisplayInchToMillimeter = 2.54;
+const double kDisplayInchToMillimeter = 25.4;
//Battery
const double kRemainingBatteryChargeMax = 100.0;
const int kVconfErrorNone = 0;
@@ -306,7 +306,7 @@ PlatformResult SysteminfoPropertiesManager::ReportDisplay(picojson::object* out)
//FETCH PHYSICAL WIDTH
if (dotsPerInchWidth != 0 && screenWidth != 0) {
- physicalWidth = (screenWidth / dotsPerInchWidth) * kDisplayInchToMillimeter;
+ physicalWidth = (static_cast(screenWidth) / dotsPerInchWidth) * kDisplayInchToMillimeter;
} else {
std::string log_msg = "Failed to get physical screen width value";
LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(),
@@ -315,7 +315,7 @@ PlatformResult SysteminfoPropertiesManager::ReportDisplay(picojson::object* out)
//FETCH PHYSICAL HEIGHT
if (dotsPerInchHeight != 0 && screenHeight != 0) {
- physicalHeight = (screenHeight / dotsPerInchHeight) * kDisplayInchToMillimeter;
+ physicalHeight = (static_cast(screenHeight) / dotsPerInchHeight) * kDisplayInchToMillimeter;
} else {
std::string log_msg = "Failed to get physical screen height value";
LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(),
--
2.7.4
From 0f62135121efde556d1378c5e798080388562f63 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 19 Jul 2017 13:26:34 +0200
Subject: [PATCH 08/16] [HAM] Adding casting int64_t to float
SVACE detected problem with code NO_CAST.INTEGER_DIVISION (25137).
[Verification] Code compiles, TCT HAM passed 100%.
Change-Id: Ie48c2250b70f79c29ea002d2c1e9b89f81e0ac24
Signed-off-by: Szymon Jastrzebski
---
src/humanactivitymonitor/humanactivitymonitor_manager.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
index 526bef7..de845e9 100755
--- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc
+++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
@@ -1336,10 +1336,12 @@ HumanActivityMonitorManager::HumanActivityMonitorManager()
LOGGER(DEBUG) << " pedometer_data->diffs_coun: " << pedometer_data->diffs_count;
if (pedometer_data->diffs_count > 0) {
for (int i = 0; i < pedometer_data->diffs_count; ++i) {
- InsertStepDifference(pedometer_data->diffs[i].steps, getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, &diffs);
+ InsertStepDifference(pedometer_data->diffs[i].steps,
+ static_cast(getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000), &diffs);
}
} else {
- InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs);
+ InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0,
+ static_cast(getCurrentTimeStamp(pedometer_data->timestamp) / 1000), &diffs);
}
steps_so_far = pedometer_data->steps();
--
2.7.4
From c86d687cee1569689110f681257170dd7bcf7344 Mon Sep 17 00:00:00 2001
From: Tomasz Marciniak
Date: Thu, 13 Jul 2017 15:35:18 +0200
Subject: [PATCH 09/16] [NBS] Add support for ipv6 addresses.
[Verification] Code compiles.
TCT pass rate is 100% (24/24/0/0/0)
Change-Id: Iee84d0ba90acfb78ed33c0f759430ffb05644efb
Signed-off-by: Tomasz Marciniak
---
.../networkbearerselection_manager.cc | 32 ++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/networkbearerselection/networkbearerselection_manager.cc b/src/networkbearerselection/networkbearerselection_manager.cc
index 34b23e1..4c3ff43 100644
--- a/src/networkbearerselection/networkbearerselection_manager.cc
+++ b/src/networkbearerselection/networkbearerselection_manager.cc
@@ -358,6 +358,7 @@ void NetworkBearerSelectionManager::registStateChangeListener(
LoggerD("enter");
char* interfaceName = nullptr;
char* hostAddr = nullptr;
+ char* gateway = nullptr;
std::unique_ptr host_addr_ptr(nullptr, &std::free);
struct addrinfo* servinfo = nullptr;
@@ -365,6 +366,9 @@ void NetworkBearerSelectionManager::registStateChangeListener(
if (interfaceName) {
free(interfaceName);
}
+ if (gateway) {
+ free(gateway);
+ }
freeaddrinfo(servinfo);
};
@@ -391,12 +395,15 @@ void NetworkBearerSelectionManager::registStateChangeListener(
struct in_addr *addr = nullptr;
if (AF_INET == servinfo->ai_family) {
+ LoggerD("IPv4 address");
struct sockaddr_in *ipv = (struct sockaddr_in *)servinfo->ai_addr;
addr = &(ipv->sin_addr);
} else {
+ LoggerD("IPv6 address");
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)servinfo->ai_addr;
addr = (struct in_addr *) &(ipv6->sin6_addr);
}
+
if (nullptr == inet_ntop(servinfo->ai_family, addr, hostAddr, servinfo->ai_addrlen)) {
LoggerE("Error while calling inet_ntop()");
destroyProfileHandle();
@@ -414,8 +421,29 @@ void NetworkBearerSelectionManager::registStateChangeListener(
LoggerE("Callback register is failed.");
destroyProfileHandle();
} else {
- if (connection_add_route(m_connection_handle_, interfaceName, hostAddr) !=
- CONNECTION_ERROR_NONE) {
+ int ret = CONNECTION_ERROR_NONE;
+ if (AF_INET == servinfo->ai_family) {
+ LoggerD("IPv4 add route");
+ ret = connection_add_route(m_connection_handle_, interfaceName, hostAddr);
+ } else if (AF_INET6 == servinfo->ai_family) {
+ LoggerD("IPv6 add route");
+ ret = connection_profile_get_gateway_address(
+ m_profile_handle_, CONNECTION_ADDRESS_FAMILY_IPV6, &gateway);
+
+ if (CONNECTION_ERROR_NONE != ret) {
+ LoggerD("Error %d", ret);
+ makeErrorCallback(domain_name, kPlatformError);
+ return;
+ }
+
+ ret = connection_add_route_ipv6(m_connection_handle_, interfaceName, hostAddr, gateway);
+ } else {
+ LoggerE("Unknown ai_family address");
+ makeErrorCallback(domain_name, kPlatformError);
+ return;
+ }
+
+ if (CONNECTION_ERROR_NONE != ret) {
LoggerE("add route is failed.");
connection_profile_unset_state_changed_cb(m_profile_handle_);
makeErrorCallback(domain_name, kPlatformError);
--
2.7.4
From 9443632a28127749efec1afe3e5b8b22ed8fb5f3 Mon Sep 17 00:00:00 2001
From: Michal Bistyga
Date: Thu, 20 Jul 2017 15:22:41 +0200
Subject: [PATCH 10/16] [spec][sensor]Enabling sensor support for TW2 emul
Change-Id: I0279827bb9294d3efcf3470f019ad84c2b3ddb9e
Signed-off-by: Michal Bistyga
---
packaging/webapi-plugins.spec | 1 +
1 file changed, 1 insertion(+)
diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec
index dcb78cb..e79ea05 100644
--- a/packaging/webapi-plugins.spec
+++ b/packaging/webapi-plugins.spec
@@ -885,6 +885,7 @@ popd
%define tizen_wearable_feature_telephony_support 1
%define tizen_wearable_feature_callhistory_support 1
%define tizen_wearable_feature_nbs_support 1
+%define tizen_wearable_feature_sensor_support 1
GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=wearable -Dprivilege_engine=%{tizen_wearable_privilege_engine}"
GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
--
2.7.4
From 48cc9e594c363c3d212825e6e3aad56bb2fdd082 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 21 Jul 2017 08:19:09 +0200
Subject: [PATCH 11/16] [version] 1.92
Change-Id: I8a2845d28e334b35300df8b82417e8510a228be6
Signed-off-by: Piotr Kosko
---
packaging/webapi-plugins.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec
index 926b460..04334f3 100644
--- a/packaging/webapi-plugins.spec
+++ b/packaging/webapi-plugins.spec
@@ -10,7 +10,7 @@
%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
Name: webapi-plugins
-Version: 1.91
+Version: 1.92
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From 35a750bb5158e8489f2cc14f928a97e42b5d4fa7 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 21 Jul 2017 08:27:21 +0200
Subject: [PATCH 12/16] Revert "Merge "[version] 1.92" into tizen"
This reverts commit 8e9d32ce4179a97f00a92244b69c6bdca7c3bfb3, reversing
changes made to b4ea08a3cd8c5cc6bbba2a6ca6adf8d1b81b5888.
Change-Id: I5921609c2573fff0cd7b82b7cb22752c568d6579
---
.../humanactivitymonitor_manager.cc | 6 ++--
src/messaging/message.cc | 4 ---
.../networkbearerselection_manager.cc | 32 ++--------------------
src/systeminfo/systeminfo_properties_manager.cc | 6 ++--
4 files changed, 7 insertions(+), 41 deletions(-)
diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
index de845e9..526bef7 100755
--- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc
+++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
@@ -1336,12 +1336,10 @@ HumanActivityMonitorManager::HumanActivityMonitorManager()
LOGGER(DEBUG) << " pedometer_data->diffs_coun: " << pedometer_data->diffs_count;
if (pedometer_data->diffs_count > 0) {
for (int i = 0; i < pedometer_data->diffs_count; ++i) {
- InsertStepDifference(pedometer_data->diffs[i].steps,
- static_cast(getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000), &diffs);
+ InsertStepDifference(pedometer_data->diffs[i].steps, getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, &diffs);
}
} else {
- InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0,
- static_cast(getCurrentTimeStamp(pedometer_data->timestamp) / 1000), &diffs);
+ InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0, getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs);
}
steps_so_far = pedometer_data->steps();
diff --git a/src/messaging/message.cc b/src/messaging/message.cc
index 14f3763..57703b1 100755
--- a/src/messaging/message.cc
+++ b/src/messaging/message.cc
@@ -592,10 +592,6 @@ PlatformResult addSingleEmailAttachment(std::shared_ptr message,
if (ret.IsError()) return ret;
email_attachment_data_t* tmp = (email_attachment_data_t*)calloc(1, sizeof(email_attachment_data_t));
- if (nullptr == tmp) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Unknown error while adding attachment.");
- }
tmp->attachment_name = strdup(att->getShortFileName().c_str());
tmp->attachment_path = strdup(std::string(dirPath + "/"
+ att->getShortFileName()).c_str());
diff --git a/src/networkbearerselection/networkbearerselection_manager.cc b/src/networkbearerselection/networkbearerselection_manager.cc
index 4c3ff43..34b23e1 100644
--- a/src/networkbearerselection/networkbearerselection_manager.cc
+++ b/src/networkbearerselection/networkbearerselection_manager.cc
@@ -358,7 +358,6 @@ void NetworkBearerSelectionManager::registStateChangeListener(
LoggerD("enter");
char* interfaceName = nullptr;
char* hostAddr = nullptr;
- char* gateway = nullptr;
std::unique_ptr host_addr_ptr(nullptr, &std::free);
struct addrinfo* servinfo = nullptr;
@@ -366,9 +365,6 @@ void NetworkBearerSelectionManager::registStateChangeListener(
if (interfaceName) {
free(interfaceName);
}
- if (gateway) {
- free(gateway);
- }
freeaddrinfo(servinfo);
};
@@ -395,15 +391,12 @@ void NetworkBearerSelectionManager::registStateChangeListener(
struct in_addr *addr = nullptr;
if (AF_INET == servinfo->ai_family) {
- LoggerD("IPv4 address");
struct sockaddr_in *ipv = (struct sockaddr_in *)servinfo->ai_addr;
addr = &(ipv->sin_addr);
} else {
- LoggerD("IPv6 address");
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)servinfo->ai_addr;
addr = (struct in_addr *) &(ipv6->sin6_addr);
}
-
if (nullptr == inet_ntop(servinfo->ai_family, addr, hostAddr, servinfo->ai_addrlen)) {
LoggerE("Error while calling inet_ntop()");
destroyProfileHandle();
@@ -421,29 +414,8 @@ void NetworkBearerSelectionManager::registStateChangeListener(
LoggerE("Callback register is failed.");
destroyProfileHandle();
} else {
- int ret = CONNECTION_ERROR_NONE;
- if (AF_INET == servinfo->ai_family) {
- LoggerD("IPv4 add route");
- ret = connection_add_route(m_connection_handle_, interfaceName, hostAddr);
- } else if (AF_INET6 == servinfo->ai_family) {
- LoggerD("IPv6 add route");
- ret = connection_profile_get_gateway_address(
- m_profile_handle_, CONNECTION_ADDRESS_FAMILY_IPV6, &gateway);
-
- if (CONNECTION_ERROR_NONE != ret) {
- LoggerD("Error %d", ret);
- makeErrorCallback(domain_name, kPlatformError);
- return;
- }
-
- ret = connection_add_route_ipv6(m_connection_handle_, interfaceName, hostAddr, gateway);
- } else {
- LoggerE("Unknown ai_family address");
- makeErrorCallback(domain_name, kPlatformError);
- return;
- }
-
- if (CONNECTION_ERROR_NONE != ret) {
+ if (connection_add_route(m_connection_handle_, interfaceName, hostAddr) !=
+ CONNECTION_ERROR_NONE) {
LoggerE("add route is failed.");
connection_profile_unset_state_changed_cb(m_profile_handle_);
makeErrorCallback(domain_name, kPlatformError);
diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc
index c9b7a37..955719b 100644
--- a/src/systeminfo/systeminfo_properties_manager.cc
+++ b/src/systeminfo/systeminfo_properties_manager.cc
@@ -43,7 +43,7 @@ using common::ErrorCode;
namespace {
const std::string kMemoryStateNormal = "NORMAL";
const std::string kMemoryStateWarinig = "WARNING";
-const double kDisplayInchToMillimeter = 25.4;
+const double kDisplayInchToMillimeter = 2.54;
//Battery
const double kRemainingBatteryChargeMax = 100.0;
const int kVconfErrorNone = 0;
@@ -367,7 +367,7 @@ PlatformResult SysteminfoPropertiesManager::ReportDisplay(picojson::object* out)
//FETCH PHYSICAL WIDTH
if (dotsPerInchWidth != 0 && screenWidth != 0) {
- physicalWidth = (static_cast(screenWidth) / dotsPerInchWidth) * kDisplayInchToMillimeter;
+ physicalWidth = (screenWidth / dotsPerInchWidth) * kDisplayInchToMillimeter;
} else {
std::string log_msg = "Failed to get physical screen width value";
LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(),
@@ -376,7 +376,7 @@ PlatformResult SysteminfoPropertiesManager::ReportDisplay(picojson::object* out)
//FETCH PHYSICAL HEIGHT
if (dotsPerInchHeight != 0 && screenHeight != 0) {
- physicalHeight = (static_cast(screenHeight) / dotsPerInchHeight) * kDisplayInchToMillimeter;
+ physicalHeight = (screenHeight / dotsPerInchHeight) * kDisplayInchToMillimeter;
} else {
std::string log_msg = "Failed to get physical screen height value";
LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(),
--
2.7.4
From a1139ec8bb294a186fca985bc827711b4115d2fa Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 21 Jul 2017 08:19:09 +0200
Subject: [PATCH 13/16] [version] 1.92
Change-Id: If809da9009b050536c900907457f633c60c606de
Signed-off-by: Piotr Kosko
---
packaging/webapi-plugins.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec
index 926b460..04334f3 100644
--- a/packaging/webapi-plugins.spec
+++ b/packaging/webapi-plugins.spec
@@ -10,7 +10,7 @@
%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
Name: webapi-plugins
-Version: 1.91
+Version: 1.92
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From c3ed3fa087f172dee746423044786372dabd4722 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 21 Jul 2017 11:43:43 +0200
Subject: [PATCH 14/16] [HAM] fixed SVACE issue
[Verification] HAM tct 100%
Change-Id: Ibba5969d26a0eb95b4320ab1c62c276d7454d68f
Signed-off-by: Piotr Kosko
---
src/humanactivitymonitor/humanactivitymonitor_manager.cc | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
index de845e9..dda7ba1 100755
--- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc
+++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc
@@ -173,13 +173,13 @@ static int64_t getCurrentTimeStamp(unsigned long long evTime)
return timeStamp;
}
-void InsertStepDifference(float step_difference, float timestamp, picojson::array* out) {
+void InsertStepDifference(float step_difference, int64_t timestamp, picojson::array* out) {
ScopeLogger();
picojson::object d;
d.insert(std::make_pair(kStepCountDifference, picojson::value(step_difference)));
- d.insert(std::make_pair(kTimestamp, picojson::value(timestamp)));
+ d.insert(std::make_pair(kTimestamp, picojson::value(static_cast(timestamp))));
out->push_back(picojson::value{d});
}
@@ -1337,11 +1337,11 @@ HumanActivityMonitorManager::HumanActivityMonitorManager()
if (pedometer_data->diffs_count > 0) {
for (int i = 0; i < pedometer_data->diffs_count; ++i) {
InsertStepDifference(pedometer_data->diffs[i].steps,
- static_cast(getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000), &diffs);
+ getCurrentTimeStamp(pedometer_data->diffs[i].timestamp) / 1000, &diffs);
}
} else {
InsertStepDifference(steps_so_far > 0.0 ? pedometer_data->steps() - steps_so_far : 0.0,
- static_cast(getCurrentTimeStamp(pedometer_data->timestamp) / 1000), &diffs);
+ getCurrentTimeStamp(pedometer_data->timestamp) / 1000, &diffs);
}
steps_so_far = pedometer_data->steps();
--
2.7.4
From 0c38f6f582eb7b495bfe82baa8f29f6d52e87105 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 9 Aug 2017 09:21:20 +0200
Subject: [PATCH 15/16] [Application] Refactoring GetBatteryUsageInfo method
The refactoring is needed for future features,
which use Context Native API.
[Verification] Code compiles
Change-Id: Iadae3cbf53ef9f4c338e4dc18edd4c1eb26cb001
Signed-off-by: Szymon Jastrzebski
---
src/application/application_manager.cc | 223 +++++++++++++++++++--------------
src/application/application_manager.h | 13 ++
2 files changed, 144 insertions(+), 92 deletions(-)
diff --git a/src/application/application_manager.cc b/src/application/application_manager.cc
index 8af357a..25e5275 100755
--- a/src/application/application_manager.cc
+++ b/src/application/application_manager.cc
@@ -29,9 +29,6 @@
#include
#include
#include
-#ifdef TIZEN_MOBILE
-#include
-#endif
#include "common/current_application.h"
#include "common/logger.h"
@@ -99,6 +96,10 @@ const std::map event_map_ = {
{SYSTEM_EVENT_DATA_ROAMING_STATE, EVENT_KEY_DATA_ROAMING_STATE},
{SYSTEM_EVENT_FONT_SET, EVENT_KEY_FONT_SET}
};
+
+#ifdef TIZEN_MOBILE
+const int kMaximumRetrievedObjects = 30;
+#endif
}
ApplicationManager::ApplicationManager(ApplicationInstance& instance) :
@@ -1162,121 +1163,75 @@ void ApplicationManager::GetBatteryUsageInfo(const picojson::value& args, picojs
LoggerD("Entered");
#ifdef TIZEN_MOBILE
- context_history_list_h list = nullptr;
- context_history_h handle = nullptr;
- context_history_filter_h filter = nullptr;
-
- SCOPE_EXIT {
- context_history_list_destroy(list);
- context_history_destroy(handle);
- context_history_filter_destroy(filter);
- };
-
- int ret = context_history_create(&handle);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to create context handle."), out,
- ("Failed to create context handle: %d (%s)", ret, get_error_message(ret)));
- return;
- }
-
- ret = context_history_filter_create(&filter);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to create filter handle."), out,
- ("Failed to create filter handle: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ auto modify_filter_cb = [](const picojson::value& args, const context_history_filter_h filter,
+ context_history_data_e* data_type_out) -> PlatformResult {
+ LoggerD("Entered");
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int limit = kMaximumRetrievedObjects;
+ if (args.contains("limit")) {
+ limit = static_cast(args.get("limit").get());
+ }
- if (args.contains("limit")) {
- const int limit = static_cast(args.get("limit").get());
ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(
- PlatformResult(ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value."), out,
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value.",
("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
- return;
}
- }
- context_history_data_e date_type = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
- if (args.contains("days")) {
- const int days = static_cast(args.get("days").get());
- date_type = CONTEXT_HISTORY_BATTERY_USAGE;
- ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
+ context_history_data_e data_type_in = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(
- PlatformResult(ErrorCode::INVALID_VALUES_ERR, "days given with invalid value."), out,
- ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
- return;
+ if (args.contains("days")) {
+ const int days = static_cast(args.get("days").get());
+ data_type_in = CONTEXT_HISTORY_BATTERY_USAGE;
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
+
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "days given with invalid value.",
+ ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
}
- }
- ret = context_history_get_list(handle, date_type, filter, &list);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get list."), out,
- ("Failed to get list: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ *data_type_out = data_type_in;
- int size = 0;
- ret = context_history_list_get_count(list, &size);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get list size."), out,
- ("Failed to get list size: %d (%s)", ret, get_error_message(ret)));
- return;
- }
-
- double amount;
- char* app_id;
+ return PlatformResult(ErrorCode::NO_ERROR);
+ };
- context_history_record_h record;
- picojson::value result_array = picojson::value(
- picojson::array(size, picojson::value(picojson::object())));
- picojson::array& array_obj = result_array.get();
+ auto add_attributes_to_object =
+ [](const context_history_record_h record, picojson::object* object) -> PlatformResult {
+ LoggerD("Entered");
- for (int i = 0; i < size; ++i) {
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ double amount = 0.0;
+ char* app_id = nullptr;
SCOPE_EXIT {
free(app_id);
- context_history_record_destroy(record);
};
- app_id = nullptr;
- record = nullptr;
-
- picojson::object& object = array_obj[i].get();
-
- ret = context_history_list_get_current(list, &record);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to current record."), out,
- ("Failed to get current record: %d (%s)", ret, get_error_message(ret)));
- return;
- }
-
ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get string."), out,
- ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
- return;
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get string.",
+ ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
}
- object.insert(std::make_pair("appId", picojson::value(app_id)));
ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get amount."), out,
- ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
- return;
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get amount.",
+ ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
}
- object.insert(std::make_pair("batteryUsage", picojson::value(amount)));
- ret = context_history_list_move_next(list);
- if (CONTEXT_HISTORY_ERROR_NONE != ret && CONTEXT_HISTORY_ERROR_NO_DATA != ret) {
- LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to move iterator."), out,
- ("Failed to move iterator: %d (%s)", ret, get_error_message(ret)));
- return;
- }
+ object->insert(std::make_pair("appId", picojson::value(app_id)));
+ object->insert(std::make_pair("batteryUsage", picojson::value(amount)));
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+ };
+
+ PlatformResult result = ApplicationManager::GetContextHistory(args, out, modify_filter_cb, add_attributes_to_object);
+ if (!result) {
+ LogAndReportError(result, out);
}
- ReportSuccess(result_array, *out);
#else
// 20170510 Context API is supported only for mobile profile, other ones would result with NotSupportedError
LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "This feature is not supported on this profile."), out,
@@ -1808,6 +1763,90 @@ void ApplicationManager::OnStatusEvent(const char *type, const char *app_id,
manager->status_callback_(&event);
}
+#ifdef TIZEN_MOBILE
+PlatformResult ApplicationManager::GetContextHistory(const picojson::value& args, picojson::object* out,
+ modifyFilterCb modify_filter_cb,
+ addAttributesToObject add_attributes_to_object) {
+ LoggerD("Entered");
+ context_history_list_h list = nullptr;
+ context_history_h handle = nullptr;
+ context_history_filter_h filter = nullptr;
+
+ SCOPE_EXIT {
+ context_history_list_destroy(list);
+ context_history_destroy(handle);
+ context_history_filter_destroy(filter);
+ };
+
+ int ret = context_history_create(&handle);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to create context handle.",
+ ("Failed to create context handle: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ ret = context_history_filter_create(&filter);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to create filter handle.",
+ ("Failed to create filter handle: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ context_history_data_e data_type;
+
+ PlatformResult result = modify_filter_cb(args, filter, &data_type);
+ if (!result) {
+ return result;
+ }
+
+ picojson::value result_array = picojson::value(picojson::array());
+ picojson::array& array_obj = result_array.get();
+
+ ret = context_history_get_list(handle, data_type, filter, &list);
+ if (CONTEXT_HISTORY_ERROR_NO_DATA == ret) {
+ ReportSuccess(result_array, *out);
+ return PlatformResult(ErrorCode::NO_ERROR);
+ } else if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get list.",
+ ("Failed to get list: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ int size = 0;
+ ret = context_history_list_get_count(list, &size);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get list size.",
+ ("Failed to get list size: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ array_obj.resize(size, picojson::value(picojson::object()));
+
+ for (int i = 0; i < size; ++i) {
+ context_history_record_h record = nullptr;
+ SCOPE_EXIT {
+ context_history_record_destroy(record);
+ };
+
+ ret = context_history_list_get_current(list, &record);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get current record.",
+ ("Failed to get current record: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ result = add_attributes_to_object(record, &array_obj[i].get());
+ if (!result) {
+ return result;
+ }
+
+ ret = context_history_list_move_next(list);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret && CONTEXT_HISTORY_ERROR_NO_DATA != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to move iterator.",
+ ("Failed to move iterator: %d (%s)", ret, get_error_message(ret)));
+ }
+ }
+
+ ReportSuccess(result_array, *out);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+#endif
+
PlatformResult ApplicationManager::StartStatusListener(const JsonCallback& callback) {
LoggerD("Entered");
diff --git a/src/application/application_manager.h b/src/application/application_manager.h
index f80ddc1..195a216 100755
--- a/src/application/application_manager.h
+++ b/src/application/application_manager.h
@@ -25,6 +25,10 @@
#include
#include
#include
+#include
+#ifdef TIZEN_MOBILE
+#include
+#endif
#include "common/picojson.h"
#include "common/platform_result.h"
@@ -85,6 +89,15 @@ class ApplicationManager {
app_manager_event_state_e event_state,
app_manager_event_h handle,
void *user_data);
+
+#ifdef TIZEN_MOBILE
+ typedef std::function modifyFilterCb;
+ typedef std::function addAttributesToObject;
+
+ static common::PlatformResult GetContextHistory(const picojson::value& args, picojson::object* out,
+ modifyFilterCb modify_filter_cb,
+ addAttributesToObject add_attributes_to_object);
+#endif
};
} // namespace application
--
2.7.4
From df3e5eece9dbfdafb851667c4e8bde99b953da8a Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 2 Aug 2017 09:54:57 +0200
Subject: [PATCH 16/16] [Application] Refactoring getBatteryUsageInfo method
into async method
[Verification] Code compiles, manually tested with chromium console
Change-Id: I7b891980977b59c799d302d4799a2cc20144a258
Signed-off-by: Szymon Jastrzebski
---
src/application/application_api.js | 27 +++++--
src/application/application_instance.cc | 2 +-
src/application/application_manager.cc | 137 +++++++++++++++++++-------------
src/application/application_manager.h | 10 +--
4 files changed, 107 insertions(+), 69 deletions(-)
diff --git a/src/application/application_api.js b/src/application/application_api.js
index d1e57eb..12bfeef 100755
--- a/src/application/application_api.js
+++ b/src/application/application_api.js
@@ -499,6 +499,16 @@ ApplicationManager.prototype.getAppMetaData = function() {
ApplicationManager.prototype.getBatteryUsageInfo = function() {
var args = AV.validateMethod(arguments, [
{
+ name: 'successCallback',
+ type: AV.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ {
name: 'days',
type: AV.Types.LONG,
optional: true,
@@ -521,16 +531,17 @@ ApplicationManager.prototype.getBatteryUsageInfo = function() {
callArgs.limit = args.limit;
}
- var result = native.callSync('ApplicationManager_getBatteryUsageInfo', callArgs);
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(args.errorCallback, native.getErrorObject(result));
+ } else {
+ args.successCallback(native.getResultObject(result));
+ }
+ };
+
+ var result = native.call('ApplicationManager_getBatteryUsageInfo', callArgs, callback);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
- } else {
- var metaData = native.getResultObject(result);
- var data = [];
- metaData.forEach(function(i) {
- data.push(new ApplicationBatteryUsage(i));
- });
- return data;
}
};
diff --git a/src/application/application_instance.cc b/src/application/application_instance.cc
index eb4ee2d..0de967a 100755
--- a/src/application/application_instance.cc
+++ b/src/application/application_instance.cc
@@ -60,7 +60,6 @@ ApplicationInstance::ApplicationInstance() :
REGISTER_SYNC("ApplicationManager_getAppCerts", GetAppCerts);
REGISTER_SYNC("ApplicationManager_getAppSharedURI", GetAppSharedURI);
REGISTER_SYNC("ApplicationManager_getAppMetaData", GetAppMetaData);
- REGISTER_SYNC("ApplicationManager_getBatteryUsageInfo", GetBatteryUsageInfo);
REGISTER_SYNC("ApplicationManager_addAppInfoEventListener", AddAppInfoEventListener);
REGISTER_SYNC("ApplicationManager_removeAppInfoEventListener", RemoveAppInfoEventListener);
REGISTER_SYNC("ApplicationManager_addAppStatusChangeListener", AddStatusListener);
@@ -90,6 +89,7 @@ ApplicationInstance::ApplicationInstance() :
REGISTER_ASYNC("ApplicationManager_findAppControl", FindAppControl);
REGISTER_ASYNC("ApplicationManager_getAppsContext", GetAppsContext);
REGISTER_ASYNC("ApplicationManager_getAppsInfo", GetAppsInfo);
+ REGISTER_ASYNC("ApplicationManager_getBatteryUsageInfo", GetBatteryUsageInfo);
#undef REGISTER_ASYNC
}
diff --git a/src/application/application_manager.cc b/src/application/application_manager.cc
index 25e5275..354582d 100755
--- a/src/application/application_manager.cc
+++ b/src/application/application_manager.cc
@@ -1159,79 +1159,106 @@ void ApplicationManager::GetAppSharedUri(const std::string& app_id, picojson::ob
ReportSuccess(result, *out);
}
-void ApplicationManager::GetBatteryUsageInfo(const picojson::value& args, picojson::object* out) {
+#ifdef TIZEN_MOBILE
+PlatformResult ApplicationManager::BatteryUsageFilter(const picojson::value& args, const context_history_filter_h filter,
+ context_history_data_e* data_type_out) {
LoggerD("Entered");
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int limit = kMaximumRetrievedObjects;
+ if (args.contains("limit")) {
+ limit = static_cast(args.get("limit").get());
+ }
-#ifdef TIZEN_MOBILE
- auto modify_filter_cb = [](const picojson::value& args, const context_history_filter_h filter,
- context_history_data_e* data_type_out) -> PlatformResult {
- LoggerD("Entered");
- int ret = CONTEXT_HISTORY_ERROR_NONE;
- int limit = kMaximumRetrievedObjects;
- if (args.contains("limit")) {
- limit = static_cast(args.get("limit").get());
- }
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
- ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value.",
+ ("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ context_history_data_e data_type_in = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
+
+ if (args.contains("days")) {
+ const int days = static_cast(args.get("days").get());
+ data_type_in = CONTEXT_HISTORY_BATTERY_USAGE;
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
if (CONTEXT_HISTORY_ERROR_NONE != ret) {
return LogAndCreateResult(
- ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value.",
- ("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ ErrorCode::INVALID_VALUES_ERR, "days given with invalid value.",
+ ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
}
+ }
- context_history_data_e data_type_in = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
-
- if (args.contains("days")) {
- const int days = static_cast(args.get("days").get());
- data_type_in = CONTEXT_HISTORY_BATTERY_USAGE;
- ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
+ *data_type_out = data_type_in;
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::INVALID_VALUES_ERR, "days given with invalid value.",
- ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
- }
- }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
- *data_type_out = data_type_in;
+PlatformResult ApplicationManager::BatteryUsageAttributes(const context_history_record_h record, picojson::object* object) {
+ LoggerD("Entered");
- return PlatformResult(ErrorCode::NO_ERROR);
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ double amount = 0.0;
+ char* app_id = nullptr;
+ SCOPE_EXIT {
+ free(app_id);
};
- auto add_attributes_to_object =
- [](const context_history_record_h record, picojson::object* object) -> PlatformResult {
- LoggerD("Entered");
+ ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get string.",
+ ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
+ }
- int ret = CONTEXT_HISTORY_ERROR_NONE;
- double amount = 0.0;
- char* app_id = nullptr;
- SCOPE_EXIT {
- free(app_id);
- };
+ ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get amount.",
+ ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
+ }
- ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get string.",
- ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
- }
+ object->insert(std::make_pair("appId", picojson::value(app_id)));
+ object->insert(std::make_pair("batteryUsage", picojson::value(amount)));
- ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
- if (CONTEXT_HISTORY_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get amount.",
- ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
- }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+#endif
- object->insert(std::make_pair("appId", picojson::value(app_id)));
- object->insert(std::make_pair("batteryUsage", picojson::value(amount)));
+void ApplicationManager::GetBatteryUsageInfo(const picojson::value& args, picojson::object* out) {
+ LoggerD("Entered");
- return PlatformResult(ErrorCode::NO_ERROR);
+#ifdef TIZEN_MOBILE
+ int callback_id = -1;
+ const auto& callback = args.get(kCallbackId);
+ if (callback.is()) {
+ callback_id = static_cast(callback.get());
+ }
+
+ auto get_battery_usage = [args](const std::shared_ptr& response)-> void {
+ LoggerD("Entered");
+ PlatformResult result = ApplicationManager::GetContextHistory(args, &response.get()->get(),
+ &ApplicationManager::BatteryUsageFilter,
+ &ApplicationManager::BatteryUsageAttributes);
+ if (!result) {
+ LogAndReportError(result, &response.get()->get());
+ }
};
- PlatformResult result = ApplicationManager::GetContextHistory(args, out, modify_filter_cb, add_attributes_to_object);
- if (!result) {
- LogAndReportError(result, out);
- }
+ auto get_battery_usage_response = [this, callback_id](
+ const std::shared_ptr& response) -> void {
+ LoggerD("Entered");
+ picojson::object& obj = response->get();
+ obj.insert(std::make_pair(kCallbackId, picojson::value(static_cast(callback_id))));
+ Instance::PostMessage(&this->instance_, response->serialize().c_str());
+ };
+
+ auto data = std::shared_ptr(new picojson::value(picojson::object()));
+
+ TaskQueue::GetInstance().Queue(
+ get_battery_usage,
+ get_battery_usage_response,
+ data);
#else
// 20170510 Context API is supported only for mobile profile, other ones would result with NotSupportedError
LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "This feature is not supported on this profile."), out,
@@ -1765,8 +1792,8 @@ void ApplicationManager::OnStatusEvent(const char *type, const char *app_id,
#ifdef TIZEN_MOBILE
PlatformResult ApplicationManager::GetContextHistory(const picojson::value& args, picojson::object* out,
- modifyFilterCb modify_filter_cb,
- addAttributesToObject add_attributes_to_object) {
+ common::PlatformResult (*modify_filter_cb)(const picojson::value&, const context_history_filter_h, context_history_data_e* data_type),
+ common::PlatformResult (*add_attributes_to_object)(const context_history_record_h, picojson::object*)) {
LoggerD("Entered");
context_history_list_h list = nullptr;
context_history_h handle = nullptr;
diff --git a/src/application/application_manager.h b/src/application/application_manager.h
index 195a216..ed4a8a1 100755
--- a/src/application/application_manager.h
+++ b/src/application/application_manager.h
@@ -91,12 +91,12 @@ class ApplicationManager {
void *user_data);
#ifdef TIZEN_MOBILE
- typedef std::function modifyFilterCb;
- typedef std::function addAttributesToObject;
-
static common::PlatformResult GetContextHistory(const picojson::value& args, picojson::object* out,
- modifyFilterCb modify_filter_cb,
- addAttributesToObject add_attributes_to_object);
+ common::PlatformResult (*)(const picojson::value&, const context_history_filter_h, context_history_data_e* data_type),
+ common::PlatformResult (*)(const context_history_record_h, picojson::object*));
+
+ static common::PlatformResult BatteryUsageFilter(const picojson::value&, const context_history_filter_h, context_history_data_e* data_type);
+ static common::PlatformResult BatteryUsageAttributes(const context_history_record_h, picojson::object*);
#endif
};
--
2.7.4