From b7f8941d093d718ebd3b10c32eddee1032d76f87 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 1 Mar 2017 12:40:45 +0100
Subject: [PATCH 01/16] [version] 1.75
Change-Id: Iacd048e44ffd0dd9dc551c6ef7243f759dbc1baa
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 4be9038..ddeb8ce 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.74
+Version: 1.75
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From dc80f733c10e3aa6e368e64df079602e4564aeab Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Mon, 6 Mar 2017 10:09:43 +0100
Subject: [PATCH 02/16] [Bluetooth] Fix GATT characteristic value change
listener
Function registered with addValueChangeListener was not called.
Change-Id: Ida88778e21884510fece8c30b93da265b246db2b
---
src/bluetooth/bluetooth_gatt_service.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc
index fce5b56..1171038 100755
--- a/src/bluetooth/bluetooth_gatt_service.cc
+++ b/src/bluetooth/bluetooth_gatt_service.cc
@@ -586,7 +586,7 @@ void BluetoothGATTService::OnCharacteristicValueChanged(
}
picojson::value result = picojson::value(picojson::object());
- picojson::object result_obj = result.get();
+ picojson::object& result_obj = result.get();
result_obj.insert(std::make_pair(kHandle, picojson::value((double)(long)characteristic)));
--
2.7.4
From 1a1584fc0d8775682b9b6ddbbe9081c8a49801a3 Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Tue, 7 Mar 2017 11:14:14 +0100
Subject: [PATCH 03/16] [Bluetooth] Fix Bluetooth LE advertising initialzation
startAdvertise() could not obtain "uuids" field of BluetoothLEAdvertiseData and "uuid" of BluetoothLEServiceData.
[Verification] After a call to startAdvertise() in application's debug mode, the device becomes discoverable by other devices with its service and serviceData.
Change-Id: Iedf239e1e79df15b32f8c4de9df397635d789eb6
Signed-off-by: Pawel Wasowski
---
src/bluetooth/bluetooth_le_adapter.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/bluetooth/bluetooth_le_adapter.cc b/src/bluetooth/bluetooth_le_adapter.cc
index 7447289..b63fc32 100755
--- a/src/bluetooth/bluetooth_le_adapter.cc
+++ b/src/bluetooth/bluetooth_le_adapter.cc
@@ -105,7 +105,7 @@ class BluetoothLEServiceData : public ParsedDataHolder {
static bool ParseUUID(const picojson::value& obj,
BluetoothLEServiceData* out) {
LoggerD("Entered");
- const auto& uuid = obj.get("serviceuuid");
+ const auto& uuid = obj.get("uuid");
if (uuid.is()) {
out->uuid_ = uuid.get();
} else {
@@ -261,7 +261,7 @@ class BluetoothLEAdvertiseData : public ParsedDataHolder {
static bool ParseServiceUUIDs(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
LoggerD("Entered");
- const auto& service_uuids = obj.get("serviceuuids");
+ const auto& service_uuids = obj.get("uuids");
if (service_uuids.is()) {
for (const auto& i : service_uuids.get()) {
if (i.is()) {
--
2.7.4
From 68f7df1a50ca9dcef7cd97857794d13c0a448b8c Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Tue, 7 Mar 2017 11:30:43 +0100
Subject: [PATCH 04/16] [Bluetooth] Fix typo in log message format string
[Verification] Proper log message appears in sdb dlog.
Change-Id: I43ea562f1e90034097f97c2c3a348284112b5f44
Signed-off-by: Pawel Wasowski
---
src/bluetooth/bluetooth_gatt_service.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc
index 1171038..98d0b53 100755
--- a/src/bluetooth/bluetooth_gatt_service.cc
+++ b/src/bluetooth/bluetooth_gatt_service.cc
@@ -576,7 +576,7 @@ common::PlatformResult BluetoothGATTService::GetServiceAllUuids(
void BluetoothGATTService::OnCharacteristicValueChanged(
bt_gatt_h characteristic, char* value, int length, void* user_data) {
- LoggerD("Entered, characteristic: [%p], len: [d], user_data: [%p]", characteristic, length, user_data);
+ LoggerD("Entered, characteristic: [%p], len: [%d], user_data: [%p]", characteristic, length, user_data);
auto service = static_cast(user_data);
--
2.7.4
From 413b911df17e420f85e3bcb19e5fd61f5811374b Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Tue, 7 Mar 2017 12:38:30 +0100
Subject: [PATCH 05/16] [Common] Added cache for mapping privileges
[Feature] Mapped privileges are stored in static map and there
is no need to connect to database on each call. This would increase
the performance of webapi calls, when performed repeatedly.
[Verification] Checking privileges works, checked with chrome console.
Privilege TCT 100% passrate.
Change-Id: Ie25b636412715e2d1678c9d382d923e4be162256
Signed-off-by: Piotr Kosko
---
src/common/tools.cc | 120 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 78 insertions(+), 42 deletions(-)
diff --git a/src/common/tools.cc b/src/common/tools.cc
index 8a6a3d3..638352f 100644
--- a/src/common/tools.cc
+++ b/src/common/tools.cc
@@ -266,6 +266,13 @@ PlatformResult CheckAccess(const std::string& privilege) {
PlatformResult CheckAccess(const std::vector& privileges) {
LoggerD("Enter");
+ // Local cache of mapped privilege strings. This routine can be called many times, especially
+ // during application launch, generating a high overhead of retrieving mapped privileges from
+ // the underlying databases. This is especially the case since the same mappings can end up
+ // being retrieved several times.
+ using MappedPrivilegeCache = std::map>;
+ static MappedPrivilegeCache mapped_privilege_cache;
+
std::string api_version;
PlatformResult res = common::tools::GetPkgApiVersion(&api_version);
if (res.IsError()) {
@@ -283,30 +290,45 @@ PlatformResult CheckAccess(const std::vector& privileges) {
g_list_free(mapped_glist);
};
- input_glist = g_list_append(input_glist, (void*)input_priv.c_str());
- int ret = privilege_manager_get_mapped_privilege_list(api_version.c_str(),
- PRVMGR_PACKAGE_TYPE_WRT,
- input_glist,
- &mapped_glist);
- if (ret != PRVMGR_ERR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get mapped privilege list");
- }
-
- LoggerD("Mapped privileges:");
- std::vector mapped_vector;
- auto push_elem = [](gpointer data, gpointer user_data) -> void {
- if (data && user_data) {
- std::vector* mapped_vector =
- static_cast*>(user_data);
- char* char_data = static_cast(data);
- mapped_vector->push_back(char_data);
- LoggerD("mapped to: %s", char_data);
+ std::vector* mapped_vector_ptr = nullptr;
+
+ // Check if mapped privilege is in local cache first
+ MappedPrivilegeCache::const_iterator it = mapped_privilege_cache.find(input_priv);
+ if (mapped_privilege_cache.end() == it) {
+ LoggerD("Mapped privileges - need to be fetched from database");
+ // Not in cache - retrieve from underlying databases.
+ input_glist = g_list_append(input_glist, (void*)input_priv.c_str());
+ int ret = privilege_manager_get_mapped_privilege_list(api_version.c_str(),
+ PRVMGR_PACKAGE_TYPE_WRT,
+ input_glist,
+ &mapped_glist);
+ if (PRVMGR_ERR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get mapped privilege list");
}
- };
- g_list_foreach (mapped_glist, push_elem, &mapped_vector);
- if (!AccessControl::GetInstance().CheckAccess(mapped_vector)){
- for (const auto& mapped_priv : mapped_vector) {
+ // initialize empty cache vector
+ mapped_privilege_cache[input_priv] = std::vector();
+ LoggerD("Mapped privileges:");
+ auto push_elem = [](gpointer data, gpointer user_data) -> void {
+ if (data && user_data) {
+ std::vector* mapped_vector =
+ static_cast*>(user_data);
+ char* char_data = static_cast(data);
+ mapped_vector->push_back(char_data);
+ LoggerD("mapped to: %s", char_data);
+ }
+ };
+ // fill the vector with data
+ g_list_foreach (mapped_glist, push_elem, &mapped_privilege_cache[input_priv]);
+ mapped_vector_ptr = &mapped_privilege_cache[input_priv];
+ } else {
+ // Retrieve from local cache
+ LoggerD("Mapped privileges already in cache");
+ mapped_vector_ptr = (std::vector*) &(it->second);
+ }
+
+ if (!AccessControl::GetInstance().CheckAccess(*mapped_vector_ptr)){
+ for (const auto& mapped_priv : *mapped_vector_ptr) {
LoggerD("Access to privilege: %s has been denied.", mapped_priv.c_str());
}
return PlatformResult(ErrorCode::SECURITY_ERR, "Permission denied");
@@ -318,6 +340,12 @@ PlatformResult CheckAccess(const std::vector& privileges) {
PlatformResult GetPkgApiVersion(std::string* api_version) {
LoggerD("Entered");
+ // Local cache of API version string. This can be expensive to retrieve from
+ // underlying databases and this routine can be called many times during
+ // application launch.
+ static std::string cached_api_version;
+ static int cached_pid = -1;
+
char* app_id = nullptr;
char* pkgid = nullptr;
char* api_ver = nullptr;
@@ -340,32 +368,40 @@ PlatformResult GetPkgApiVersion(std::string* api_version) {
};
pid_t pid = getpid();
- int ret = app_manager_get_app_id(pid, &app_id);
- if (ret != APP_MANAGER_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app id");
- }
+ if (cached_pid == pid) {
+ *api_version = cached_api_version; // Retrieve from local cache
+ } else {
+ int ret = app_manager_get_app_id(pid, &app_id);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app id");
+ }
- ret = app_info_create(app_id, &app_handle);
- if (ret != APP_MANAGER_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app info");
- }
+ ret = app_info_create(app_id, &app_handle);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get app info");
+ }
- ret = app_info_get_package(app_handle, &pkgid);
- if ((ret != APP_MANAGER_ERROR_NONE) || (pkgid == nullptr)) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkg id");
- }
+ ret = app_info_get_package(app_handle, &pkgid);
+ if ((ret != APP_MANAGER_ERROR_NONE) || (pkgid == nullptr)) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkg id");
+ }
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, getuid(), &pkginfo_handle);
- if (ret != PMINFO_R_OK) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkginfo_h");
- }
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, getuid(), &pkginfo_handle);
+ if (ret != PMINFO_R_OK) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get pkginfo_h");
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo_handle, &api_ver);
+ if (ret != PMINFO_R_OK) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get api version");
+ }
+
+ cached_api_version = api_ver; // Save in local cache
+ cached_pid = pid;
- ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo_handle, &api_ver);
- if (ret != PMINFO_R_OK) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Fail to get api version");
+ *api_version = api_ver;
}
- *api_version = api_ver;
return PlatformResult(ErrorCode::NO_ERROR);
}
--
2.7.4
From a3816b0c239d3ad3f4c78b5c43acd29124eddd24 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 8 Mar 2017 08:52:10 +0100
Subject: [PATCH 06/16] [Download] Fix in onFailed cleaning resources
[Feature] missing unregistration was added
[Verification] TCT passrate 100%.
Change-Id: I363d1bf41496f05128620c3d00c9f0cb2ac839b0
Signed-off-by: Piotr Kosko
---
src/download/download_instance.cc | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/download/download_instance.cc b/src/download/download_instance.cc
index eeb071b..0950619 100755
--- a/src/download/download_instance.cc
+++ b/src/download/download_instance.cc
@@ -443,7 +443,17 @@ gboolean DownloadInstance::OnFailed(void* user_data) {
("download_get_error error: %d (%s)", error, get_error_message(error)));
}
- int ret = download_destroy(diPtr->download_id);
+ int ret = download_unset_state_changed_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ }
+
+ ret = download_unset_progress_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ }
+
+ ret = download_destroy(diPtr->download_id);
if (DOWNLOAD_ERROR_NONE != ret) {
LoggerE("%s", get_error_message(ret));
}
--
2.7.4
From 85751b0e0b5268b9bd8b1d43c7441afd2b7a2048 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 8 Mar 2017 11:31:28 +0100
Subject: [PATCH 07/16] [version] 1.76
Change-Id: I13301870fffc46da89e2ade6331798d617e0f500
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 ddeb8ce..456b61c 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.75
+Version: 1.76
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From 18afa4ce89f133e378f7e0bb0f26b4b4de9d71d3 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Mon, 13 Mar 2017 11:31:34 +0100
Subject: [PATCH 08/16] [Alarm] Fixing AlarmRelative/Absolute .period
When alarm.period wasn't set by user,
tizen.alarm.getAll()/get() should set alarm.period to null, not 0.
After adding alarm period is updated.
[Verification] TCTs passed 59/1/0/0
Failing test case needs to be fixed
Change-Id: I800477b4cefbdfe152b7abb0db750b6713cd0ed3
Signed-off-by: Szymon Jastrzebski
---
src/alarm/alarm_api.js | 89 +++++++++++++++++++++++++++++++++++++++++-----
src/alarm/alarm_manager.cc | 45 ++++++++++++++++++-----
2 files changed, 117 insertions(+), 17 deletions(-)
diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js
index 78f22ad..47725dc 100755
--- a/src/alarm/alarm_api.js
+++ b/src/alarm/alarm_api.js
@@ -30,6 +30,20 @@ var AlarmManager = function () {
});
};
+var EditManager = function() {
+ this.canEdit = false;
+};
+
+EditManager.prototype.allow = function() {
+ this.canEdit = true;
+};
+
+EditManager.prototype.disallow = function() {
+ this.canEdit = false;
+};
+
+var _edit = new EditManager();
+
function InternalData_(data) {
if (!(this instanceof InternalData_)) {
return new InternalData_(data);
@@ -90,12 +104,15 @@ AlarmManager.prototype.add = function () {
callArgs.type = type;
callArgs.seconds = Converter.toString(seconds);
+ callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
var result = native.callSync('AlarmManager_add', callArgs);
if (native.isFailure(result)) {
throw native.getErrorObject(result);
} else {
+ _edit.allow();
UpdateInternalData_(args.alarm, native.getResultObject(result));
+ _edit.disallow();
}
};
@@ -202,16 +219,38 @@ tizen.AlarmRelative = function(delay, period, internal) {
var m_delay = Converter.toLong(delay);
if (arguments.length >= 2) {
- m_period = Converter.toLong(period, true);
+ if(!T.isNullOrUndefined(period)){
+ m_period = Converter.toLong(period, true);
+ }
}
Alarm.call(this, internal);
Object.defineProperties(this, {
- delay: { value: m_delay, writable: false, enumerable: true},
- period: { value: m_period, writable: false, enumerable: true}
+ delay: {
+ get: function() {
+ return m_delay;
+ },
+ set: function(v) {
+ if (_edit.canEdit && v) {
+ m_delay = Converter.toLong(v.delay);
+ }
+ },
+ enumerable: true
+ },
+ period: {
+ get: function() {
+ return m_period;
+ },
+ set: function(v) {
+ if (_edit.canEdit && v) {
+ m_period = Converter.toLong(v.period);
+ }
+ },
+ enumerable: true
+ }
});
-}
+};
tizen.AlarmRelative.prototype = new Alarm();
@@ -261,7 +300,9 @@ tizen.AlarmAbsolute = function(date, second, internal) {
if(T.isArray(second)){
m_daysOfWeek = second;
} else {
- m_period = Converter.toLong(second);
+ if(!T.isNullOrUndefined(second)){
+ m_period = Converter.toLong(second);
+ }
}
}
@@ -271,11 +312,41 @@ tizen.AlarmAbsolute = function(date, second, internal) {
}
makeDateConst(m_date);
Object.defineProperties(this, {
- date: { value: m_date, writable: false, enumerable: true},
- period: { value: m_period, writable: false, enumerable: true},
- daysOfTheWeek: { value: m_daysOfWeek, writable: false, enumerable: true}
+ date: {
+ get: function() {
+ return m_date;
+ },
+ set: function(v) {
+ if (_edit.canEdit && T.isDate(v.date)) {
+ m_date = v.date;
+ }
+ },
+ enumerable: true
+ },
+ period: {
+ get: function() {
+ return m_period;
+ },
+ set: function(v) {
+ if (_edit.canEdit && v) {
+ m_period = Converter.toLong(v.period);
+ }
+ },
+ enumerable: true
+ },
+ daysOfTheWeek: {
+ get: function() {
+ return m_daysOfWeek;
+ },
+ set: function(v) {
+ if (_edit.canEdit && T.isArray(v.second)) {
+ m_daysOfWeek = v.second;
+ }
+ },
+ enumerable: true
+ }
});
-}
+};
tizen.AlarmAbsolute.prototype = new Alarm();
diff --git a/src/alarm/alarm_manager.cc b/src/alarm/alarm_manager.cc
index 5bc8d84..3dc9f21 100755
--- a/src/alarm/alarm_manager.cc
+++ b/src/alarm/alarm_manager.cc
@@ -111,6 +111,11 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
app_control_set_app_id(app_control, app_id.c_str());
int alarm_id = 0;
+ int period = 0;
+
+ // result object
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get();
if (kAlarmRelative == alarm_type) {
app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueRelative);
@@ -124,11 +129,15 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
}
int delay = static_cast(it_delay->second.get());
- int period = 0;
if (it_period->second.is()) {
period = static_cast(it_period->second.get());
}
+ bool isPeriodSet = false;
+ if (args.contains("isPeriodSet")) {
+ isPeriodSet = args.get("isPeriodSet").get();
+ }
+
std::string delay_str = std::to_string(delay);
int ret = app_control_add_extra_data(app_control, kAlarmRelativeDelayKey, delay_str.c_str());
if (APP_CONTROL_ERROR_NONE != ret) {
@@ -138,7 +147,7 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
return;
}
- if(period == 0){
+ if(!isPeriodSet){
ret = alarm_schedule_once_after_delay(app_control, delay, &alarm_id);
}else{
ret = alarm_schedule_after_delay(app_control, delay, period, &alarm_id);
@@ -149,6 +158,17 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
("Error while add alarm to server: %d (%s)", ret, get_error_message(ret)));
return;
}
+
+ ret = alarm_get_scheduled_period(alarm_id, &period);
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Unknown error occurred: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ if(period != 0){
+ result_obj.insert(std::make_pair("period", picojson::value(std::to_string(period))));
+ }
} else {
app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueAbsolute);
@@ -183,8 +203,17 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
if (alarm.end() != it_period && it_period->second.is()) {
app_control_add_extra_data(
app_control, kAlarmAbsoluteRecurrenceTypeKey, kAlarmAbsoluteReccurrenceTypeInterval);
- int period = static_cast(it_period->second.get());
+ period = static_cast(it_period->second.get());
ret = alarm_schedule_at_date(app_control, &start_date, period, &alarm_id);
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Adding alarm to server failed."),
+ &out,
+ ("Adding alarm to server failed: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ ret = alarm_get_scheduled_period(alarm_id, &period);
+ result_obj.insert(std::make_pair("period", picojson::value(std::to_string(period))));
} else if (alarm.end() != it_daysOfTheWeek && it_daysOfTheWeek->second.is() &&
!(it_daysOfTheWeek->second.get()).empty()) {
app_control_add_extra_data(
@@ -229,10 +258,6 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
}
}
- // result object
- picojson::value result = picojson::value(picojson::object());
- picojson::object& result_obj = result.get();
-
result_obj.insert(std::make_pair("id", picojson::value(std::to_string(alarm_id))));
ReportSuccess(result, out);
}
@@ -397,7 +422,11 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) {
obj.insert(std::make_pair("type", picojson::value(kAlarmRelative)));
obj.insert(std::make_pair("delay", picojson::value(delay_string)));
- obj.insert(std::make_pair("period", picojson::value(std::to_string(interval))));
+ if (interval != 0) {
+ //according to documentation interval will not be lower than 600,
+ //thus 0 from native means period wasn't set by user
+ obj.insert(std::make_pair("period", picojson::value(std::to_string(interval))));
+ }
} else {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred.");
}
--
2.7.4
From ef728910b19af6576c7f25f21444ffa923aac854 Mon Sep 17 00:00:00 2001
From: Tomasz Marciniak
Date: Mon, 13 Mar 2017 13:19:35 +0100
Subject: [PATCH 09/16] [Filesystem] Fix for writing data with 'w' mode
[Feature] If stream is opened with 'w' mode and file exists
its content is discarded before writing data.
[Verification] Code compiles.
TCT (Auto) pass rate 100%
Change-Id: I5579b7f17175c39a8bf57b210a2a1ff29c1e7e2e
Signed-off-by: Tomasz Marciniak
---
src/filesystem/filesystem_file.cc | 11 +++++++++--
src/filesystem/filesystem_file.h | 2 +-
src/filesystem/filesystem_instance.cc | 7 ++++++-
src/filesystem/filesystem_manager.cc | 3 ++-
src/filesystem/filesystem_manager.h | 1 +
src/filesystem/js/file_stream.js | 17 ++++++++++++++---
6 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/filesystem/filesystem_file.cc b/src/filesystem/filesystem_file.cc
index fc3d89c..a12047e 100644
--- a/src/filesystem/filesystem_file.cc
+++ b/src/filesystem/filesystem_file.cc
@@ -218,9 +218,16 @@ bool FilesystemFile::Read(FilesystemBuffer* data,
return true;
}
-bool FilesystemFile::Write(const FilesystemBuffer& data, size_t offset) {
+bool FilesystemFile::Write(const FilesystemBuffer& data, size_t offset, bool rewrite) {
LoggerD("Enter");
- FILE* file = fopen(path.c_str(), "r+");
+
+ FILE* file = nullptr;
+ if (rewrite) {
+ file = fopen(path.c_str(), "w");
+ } else {
+ file = fopen(path.c_str(), "r+");
+ }
+
if (!file) {
LoggerE("Cannot open file %s to write!", path.c_str());
return false;
diff --git a/src/filesystem/filesystem_file.h b/src/filesystem/filesystem_file.h
index 5779eaf..c7f2ece 100644
--- a/src/filesystem/filesystem_file.h
+++ b/src/filesystem/filesystem_file.h
@@ -45,7 +45,7 @@ class FilesystemFile {
FilesystemFile(const std::string& path_);
bool Read(FilesystemBuffer* data, size_t offset, size_t length);
- bool Write(const FilesystemBuffer& data, size_t offset);
+ bool Write(const FilesystemBuffer& data, size_t offset, bool rewrite);
};
} // namespace filesystem
diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc
index 54b0a2e..47ffc97 100644
--- a/src/filesystem/filesystem_instance.cc
+++ b/src/filesystem/filesystem_instance.cc
@@ -216,11 +216,13 @@ void FilesystemInstance::FileWrite(const picojson::value& args,
CHECK_EXIST(args, "location", out)
CHECK_EXIST(args, "data", out)
CHECK_EXIST(args, "offset", out)
+ CHECK_EXIST(args, "rewrite", out)
double callback_id = args.get("callbackId").get();
const std::string& location = args.get("location").get();
const std::string& data = args.get("data").get();
size_t offset = static_cast(args.get("location").get());
+ bool rewrite = static_cast(args.get("rewrite").get());
auto onSuccess = [this, callback_id]() {
LoggerD("enter");
@@ -247,6 +249,7 @@ void FilesystemInstance::FileWrite(const picojson::value& args,
location,
data,
offset,
+ rewrite,
onSuccess,
onError));
}
@@ -258,10 +261,12 @@ void FilesystemInstance::FileWriteSync(const picojson::value& args,
CHECK_EXIST(args, "location", out)
CHECK_EXIST(args, "data", out)
CHECK_EXIST(args, "offset", out)
+ CHECK_EXIST(args, "rewrite", out)
const std::string& location = args.get("location").get();
const std::string& data = args.get("data").get();
size_t offset = static_cast(args.get("offset").get());
+ bool rewrite = static_cast(args.get("rewrite").get());
auto onSuccess = [this, &out]() {
LoggerD("enter");
@@ -274,7 +279,7 @@ void FilesystemInstance::FileWriteSync(const picojson::value& args,
};
FilesystemManager::GetInstance().FileWrite(
- location, data, offset, onSuccess, onError);
+ location, data, offset, rewrite, onSuccess, onError);
}
void FilesystemInstance::FileStat(const picojson::value& args,
diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc
index 468a095..dc96e58 100644
--- a/src/filesystem/filesystem_manager.cc
+++ b/src/filesystem/filesystem_manager.cc
@@ -412,6 +412,7 @@ void FilesystemManager::FileWrite(
const std::string& path,
const std::string& data,
size_t offset,
+ bool rewrite,
const std::function& success_cb,
const std::function& error_cb) {
@@ -425,7 +426,7 @@ void FilesystemManager::FileWrite(
return;
}
- if (file.Write(buffer, offset)) {
+ if (file.Write(buffer, offset, rewrite)) {
success_cb();
} else {
LoggerE("Cannot write to file %s!", path.c_str());
diff --git a/src/filesystem/filesystem_manager.h b/src/filesystem/filesystem_manager.h
index d455ed9..b2060fb 100644
--- a/src/filesystem/filesystem_manager.h
+++ b/src/filesystem/filesystem_manager.h
@@ -101,6 +101,7 @@ class FilesystemManager {
void FileWrite(const std::string& path,
const std::string& data,
size_t offset,
+ bool rewrite,
const std::function& success_cb,
const std::function& error_cb);
diff --git a/src/filesystem/js/file_stream.js b/src/filesystem/js/file_stream.js
index 1d3f708..221f87e 100644
--- a/src/filesystem/js/file_stream.js
+++ b/src/filesystem/js/file_stream.js
@@ -68,6 +68,11 @@ function FileStream(data, mode, encoding) {
value: false,
writable: true,
enumerable: false
+ },
+ _rewrite: {
+ value: mode === 'w' ? true : false,
+ writable: true,
+ enumerable: false
}
});
}
@@ -277,7 +282,8 @@ function write() {
var data = {
location: commonFS_.toRealPath(this._file.fullPath),
offset: this.position,
- data: Base64.encodeString(args.stringData)
+ data: Base64.encodeString(args.stringData),
+ rewrite: this._rewrite
};
var result = native_.callSync('File_writeSync', data);
@@ -288,6 +294,7 @@ function write() {
can_change_size = true;
this.position = this.position + args.stringData.length;
can_change_size = false;
+ this._rewrite = false;
};
FileStream.prototype.write = function() {
@@ -314,7 +321,8 @@ function writeBytes() {
var data = {
location: commonFS_.toRealPath(this._file.fullPath),
offset: this.position,
- data: Base64.encode(args.byteData)
+ data: Base64.encode(args.byteData),
+ rewrite: this._rewrite
};
var result = native_.callSync('File_writeSync', data);
@@ -325,6 +333,7 @@ function writeBytes() {
can_change_size = true;
this.position = this.position + args.byteData.length;
can_change_size = false;
+ this._rewrite = false;
};
FileStream.prototype.writeBytes = function() {
@@ -359,7 +368,8 @@ function writeBase64() {
var data = {
location: commonFS_.toRealPath(this._file.fullPath),
offset: this.position,
- data: args.base64Data
+ data: args.base64Data,
+ rewrite: this._rewrite
};
var result = native_.callSync('File_writeSync', data);
@@ -373,6 +383,7 @@ function writeBase64() {
can_change_size = true;
this.position += decoded.length;
can_change_size = false;
+ this._rewrite = false;
};
FileStream.prototype.writeBase64 = function() {
--
2.7.4
From cbcc7502c457b34a73a69ba6a82ab6a9621288d3 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 15 Mar 2017 07:58:38 +0100
Subject: [PATCH 10/16] [version] 1.77
Change-Id: Ic2142cc6efbf4a3d7292b8e779bca13adb31eecd
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 456b61c..4b722c8 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.76
+Version: 1.77
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From 336cf253b985df0b03967dc9ebb610e31f330468 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 31 Mar 2017 11:08:20 +0200
Subject: [PATCH 11/16] [Convergence] Fixing SVACE issue
[Verification] Code compiles without errors.
Change-Id: If7ee6db3ab6939160bfec11f0afe365b606393cc
Signed-off-by: Piotr Kosko
---
src/convergence/convergence_service.cc | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/convergence/convergence_service.cc b/src/convergence/convergence_service.cc
index 4f9167e..29992d7 100644
--- a/src/convergence/convergence_service.cc
+++ b/src/convergence/convergence_service.cc
@@ -190,19 +190,17 @@ picojson::value ConvergenceService::ToJson() const {
std::vector::iterator ConvergenceService::GetChannel(const picojson::value &channel_json) {
ScopeLogger();
-
- std::vector::iterator it;
const auto id = channel_json.get(kId).get();
const auto uri = channel_json.get(kUri).get();
- for (it = opened_channels.begin(); it != opened_channels.end(); ++it) {
+ for (auto it = opened_channels.begin(); it != opened_channels.end(); ++it) {
if((*it)->GetUri() == uri && (*it)->GetId() == id) {
LoggerD("Found channel uri: [%s] id: [%s]", uri.c_str(), id.c_str());
- break;
+ return it;
}
}
- return it;
+ return opened_channels.end();
}
bool ConvergenceService::IsChannelStarted(std::vector::iterator it) {
--
2.7.4
From 22c11bc185383d4469a41c26c3041364fa0d882c Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 5 Apr 2017 10:03:41 +0200
Subject: [PATCH 12/16] [version] 1.78
Change-Id: Ia4c40566c8d77071bf45cf1568ec2af23ec480cf
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 4b722c8..699c5f9 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.77
+Version: 1.78
Release: 0
License: Apache-2.0 and BSD-3-Clause and MIT
Group: Development/Libraries
--
2.7.4
From a50607d136a621e6335c9824354d86312eb58fd0 Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 5 Apr 2017 11:01:45 +0200
Subject: [PATCH 13/16] [Feedback] Added checking if pattern is supported
before playing
If given pattern is not supported, exception will be thrown.
[Verification] Code compiles
TCT Feedback passed A 100% M 2 fails
Failed TCs will be requested to be changed
Change-Id: I6ee43602d4c06ade3a569d48978a78b2f04dccab
Signed-off-by: Szymon Jastrzebski
---
src/feedback/feedback_manager.cc | 56 ++++++++++++++++++++++++++++++----------
src/feedback/feedback_manager.h | 5 ++++
2 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/src/feedback/feedback_manager.cc b/src/feedback/feedback_manager.cc
index 381ecb5..91e0e09 100644
--- a/src/feedback/feedback_manager.cc
+++ b/src/feedback/feedback_manager.cc
@@ -92,6 +92,21 @@ feedback_type_e const & FeedbackMaps::getTypeFromMap(const std::string& type) {
return mTypeMap[type];
}
+bool FeedbackMaps::isPatternSupportChecked(const feedback_pattern_e pattern,
+ const feedback_type_e type) {
+ return mSupportedMap.find(std::make_pair(pattern, type)) != mSupportedMap.end();
+}
+
+bool FeedbackMaps::isPatternSupported(const feedback_pattern_e pattern,
+ const feedback_type_e type) {
+ return mSupportedMap[std::make_pair(pattern, type)];
+}
+
+void FeedbackMaps::setPatternSupport(const feedback_pattern_e pattern, const feedback_type_e type,
+ const bool isSupported) {
+ mSupportedMap[std::make_pair(pattern, type)] = isSupported;
+}
+
FeedbackManager::FeedbackManager(std::shared_ptr maps)
: m_feedbackMapsPtr(maps)
{
@@ -114,34 +129,47 @@ FeedbackManager::~FeedbackManager() {
}
}
-common::PlatformResult
-FeedbackManager::isPatternSupported(const std::string &pattern, const std::string &type, bool* patternStatus) {
+common::PlatformResult FeedbackManager::isPatternSupported(const std::string &pattern,
+ const std::string &type,
+ bool* patternStatus) {
LoggerD("Entered");
- int ret = feedback_is_supported_pattern(
- m_feedbackMapsPtr->getTypeFromMap(type),
- m_feedbackMapsPtr->getPatternFromMap(pattern),
- patternStatus
- );
- if(ret != FEEDBACK_ERROR_NONE) {
+ auto &pattern_e = m_feedbackMapsPtr->getPatternFromMap(pattern);
+ auto &type_e = m_feedbackMapsPtr->getTypeFromMap(type);
+ if (m_feedbackMapsPtr->isPatternSupportChecked(pattern_e, type_e)) {
+ *patternStatus = m_feedbackMapsPtr->isPatternSupported(pattern_e, type_e);
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ int ret = feedback_is_supported_pattern(type_e, pattern_e, patternStatus);
+ if (ret != FEEDBACK_ERROR_NONE) {
LoggerE("isPatternSupported failed: %d", ret);
return CodeToResult(ret, getFeedbackErrorMessage(ret).c_str());
- }
+ }
+ m_feedbackMapsPtr->setPatternSupport(pattern_e, type_e, *patternStatus);
return PlatformResult(ErrorCode::NO_ERROR);
}
common::PlatformResult FeedbackManager::play(const std::string &pattern, const std::string &type) {
LoggerD("Entered");
int ret = 0;
- if(type == "any") {
+ if (type == "any") {
ret = feedback_play(m_feedbackMapsPtr->getPatternFromMap(pattern));
} else {
- ret = feedback_play_type(m_feedbackMapsPtr->getTypeFromMap(type),
- m_feedbackMapsPtr->getPatternFromMap(pattern));
+ bool patternSupport = false;
+ auto result = isPatternSupported(pattern, type, &patternSupport);
+ if (!result) {
+ return result;
+ }
+ if (patternSupport) {
+ ret = feedback_play_type(m_feedbackMapsPtr->getTypeFromMap(type),
+ m_feedbackMapsPtr->getPatternFromMap(pattern));
+ } else {
+ return CodeToResult(FEEDBACK_ERROR_NOT_SUPPORTED, "Not supported device");
+ }
}
- if(ret != FEEDBACK_ERROR_NONE) {
+ if (ret != FEEDBACK_ERROR_NONE) {
LoggerE("play failed: %d", ret);
return CodeToResult(ret, getFeedbackErrorMessage(ret).c_str());
- }
+ }
return PlatformResult(ErrorCode::NO_ERROR);
}
diff --git a/src/feedback/feedback_manager.h b/src/feedback/feedback_manager.h
index 471ab7c..34c2a12 100644
--- a/src/feedback/feedback_manager.h
+++ b/src/feedback/feedback_manager.h
@@ -29,6 +29,7 @@ namespace feedback {
using stringPatternMap = std::map;
using stringTypeMap = std::map;
+using supportedPatternsMap = std::map, bool>;
class FeedbackMaps {
public:
@@ -36,9 +37,13 @@ class FeedbackMaps {
virtual ~FeedbackMaps();
feedback_pattern_e const & getPatternFromMap(const std::string& pattern);
feedback_type_e const & getTypeFromMap(const std::string& type);
+ bool isPatternSupportChecked(const feedback_pattern_e pattern, const feedback_type_e type);
+ bool isPatternSupported(const feedback_pattern_e pattern, const feedback_type_e type);
+ void setPatternSupport(const feedback_pattern_e pattern, const feedback_type_e type, const bool isSupported);
private:
stringTypeMap mTypeMap;
stringPatternMap mPatternMap;
+ supportedPatternsMap mSupportedMap;
};
class FeedbackManager {
--
2.7.4
From 736eabb555c2bec6fd7a8563e36f7dc4b8608768 Mon Sep 17 00:00:00 2001
From: Jakub Skowron
Date: Thu, 6 Apr 2017 10:14:56 +0200
Subject: [PATCH 14/16] [Utils] Allow global JSON object redefinition
Allow application programmer to redefine global JSON object.
In our code use xwalk.JSON instead
Change-Id: I62d57130584aea42a176633aa758b1f675d65b00
Signed-off-by: Jakub Skowron
---
src/convergence/convergence_api.js | 3 ++-
src/datacontrol/datacontrol_api.js | 8 ++++----
src/download/download_api.js | 7 ++++---
src/feedback/feedback_api.js | 5 +++--
src/messageport/messageport_api.js | 7 ++++---
src/package/package_api.js | 7 ++++---
src/power/power_api.js | 5 +++--
src/tizen/tizen_api.js | 12 ------------
src/utils/utils_api.js | 19 ++++++++++++-------
9 files changed, 36 insertions(+), 37 deletions(-)
diff --git a/src/convergence/convergence_api.js b/src/convergence/convergence_api.js
index 6b02506..120f4ab 100644
--- a/src/convergence/convergence_api.js
+++ b/src/convergence/convergence_api.js
@@ -15,6 +15,7 @@
*/
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var utils_ = xwalk.utils;
@@ -711,7 +712,7 @@ native_.addListener('APP_COMMUNICATION_SERVICE_LISTENER', function(result) {
for(var i = 0; i < result.payload.length; i++) {
if (result.payload[i].key === 'client_list') {
- var value = JSON.parse(result.payload[i].value);
+ var value = JSON_.parse(result.payload[i].value);
var client = new ClientInfo(value);
clients_array.push(client);
}
diff --git a/src/datacontrol/datacontrol_api.js b/src/datacontrol/datacontrol_api.js
index 108f57c..cb7158e 100755
--- a/src/datacontrol/datacontrol_api.js
+++ b/src/datacontrol/datacontrol_api.js
@@ -16,15 +16,15 @@
tizen.debug = extension;
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
-
var callbackId = 0;
var callbacks = {};
extension.setMessageListener(function(json) {
- var result = JSON.parse(json);
+ var result = JSON_.parse(json);
var callback = callbacks[result['callbackId']];
setTimeout(function() {
callback(result);
@@ -38,9 +38,9 @@ function nextCallbackId() {
function callNative(cmd, args) {
var json = {'cmd': cmd, 'args': args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/download/download_api.js b/src/download/download_api.js
index b47ddd0..8e5d9c1 100755
--- a/src/download/download_api.js
+++ b/src/download/download_api.js
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+var JSON_ = xwalk.JSON;
var privUtils_ = xwalk.utils;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
@@ -27,7 +28,7 @@ var requests = {};
extension.setMessageListener(function(json) {
- var result = JSON.parse(json);
+ var result = JSON_.parse(json);
var callback = callbacks[result.callbackId];
//privUtils_.log("PostMessage received: " + result.status);
@@ -70,9 +71,9 @@ function nextCallbackId() {
function callNative(cmd, args) {
var json = {'cmd': cmd, 'args': args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/feedback/feedback_api.js b/src/feedback/feedback_api.js
index 6a7f693..43ffb99 100755
--- a/src/feedback/feedback_api.js
+++ b/src/feedback/feedback_api.js
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var type_ = xwalk.utils.type;
@@ -36,9 +37,9 @@ var ExceptionMap = {
function callNative(cmd, args) {
var json = {'cmd': cmd, 'args': args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/messageport/messageport_api.js b/src/messageport/messageport_api.js
index cada46b..ab612f1 100755
--- a/src/messageport/messageport_api.js
+++ b/src/messageport/messageport_api.js
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var type_ = xwalk.utils.type;
@@ -25,7 +26,7 @@ var callbacks = {};
var ports = [];
extension.setMessageListener(function(json) {
- var msg = JSON.parse(json);
+ var msg = JSON_.parse(json);
var listeners = callbacks[msg['local_port_id']];
var rmp;
@@ -65,9 +66,9 @@ var ExceptionMap = {
function callNative(cmd, args) {
var json = {'cmd': cmd, 'args': args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/package/package_api.js b/src/package/package_api.js
index 87c45d1..fcc9fc4 100644
--- a/src/package/package_api.js
+++ b/src/package/package_api.js
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
@@ -30,7 +31,7 @@ function invokeListener(result) {
}
extension.setMessageListener(function(json) {
- var result = JSON.parse(json);
+ var result = JSON_.parse(json);
if (result.hasOwnProperty('listener')) {
setTimeout(function() {
@@ -50,9 +51,9 @@ function nextCallbackId() {
function callNative(cmd, args) {
var json = {'cmd': cmd, 'args': args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/power/power_api.js b/src/power/power_api.js
index 5be1026..f7a711d 100755
--- a/src/power/power_api.js
+++ b/src/power/power_api.js
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
@@ -44,9 +45,9 @@ var screenStateChangeListener = new ListenerManager(native_, "SCREEN_STATE_LISTE
function callNative(cmd, args) {
var json = {'cmd':cmd, 'args':args};
- var argjson = JSON.stringify(json);
+ var argjson = JSON_.stringify(json);
var resultString = extension.internal.sendSyncMessage(argjson);
- var result = JSON.parse(resultString);
+ var result = JSON_.parse(resultString);
if (typeof result !== 'object') {
throw new WebAPIException(WebAPIException.UNKNOWN_ERR);
diff --git a/src/tizen/tizen_api.js b/src/tizen/tizen_api.js
index f5f8085..eaa502b 100644
--- a/src/tizen/tizen_api.js
+++ b/src/tizen/tizen_api.js
@@ -10,14 +10,6 @@
// WebAPIException and WebAPIError definition moved to src/utils/utils_api.js
// for compliance reasons. You can find more info there.
-var _global = {};
-if (typeof window != 'undefined') {
- _global = window;
-}
-else if (typeof global != 'undefiend') {
- _global = global;
-}
-
/**
* Filter match flags.
@@ -481,7 +473,3 @@ exports.SimpleCoordinates = function(lat, lng) {
});
};
exports.SimpleCoordinates.prototype.constructor = exports.SimpleCoordinates;
-
-// Protect JSON.stringify from being overriden by application
-Object.defineProperty( _global, 'JSON', {value:JSON, writable:false, configurable:false} );
-Object.defineProperty( JSON, 'stringify', {value:JSON.stringify, writable:false, configurable:false} );
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index 85fdc33..ca61725 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -3,6 +3,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+//Object xwalk.JSON - guaranteed to not being modified by the application programmer
+var JSON_ = {stringify: JSON.stringify, parse: JSON.parse};
+Object.freeze(JSON_)
+exports.JSON = JSON_;
+
var _enableJsLogs = false;
var _global = {};
@@ -1015,7 +1020,7 @@ var NativeManager = function(extension) {
});
extension_.setMessageListener(function(json) {
- var msg = JSON.parse(json);
+ var msg = JSON_.parse(json);
var id;
if (msg.hasOwnProperty(this.CALLBACK_ID_KEY)) {
@@ -1079,7 +1084,7 @@ NativeManager.prototype.call = function(cmd, args, callback) {
};
NativeManager.prototype.callSync = function(cmd, args) {
- var request = JSON.stringify({
+ var request = JSON_.stringify({
cmd: cmd,
args: args || {}
});
@@ -1089,7 +1094,7 @@ NativeManager.prototype.callSync = function(cmd, args) {
/* C++ extension didn't set sync response using Instance::SendSyncReply */
throw new WebAPIException(WebAPIException.ABORT_ERR, "Internal error");
}
- return JSON.parse(response);
+ return JSON_.parse(response);
};
NativeManager.prototype.sendRuntimeMessage = function(msg, body) {
@@ -1343,13 +1348,13 @@ var NativeBridge = (function (extension, debug) {
var Bridge = function () {};
Bridge.prototype = {
sync: function (data) {
- var json = JSON.stringify({
+ var json = JSON_.stringify({
cmd: data.cmd,
args: data
});
if (debug) console.log('bridge.sync, json: ' + json);
var result = extension.internal.sendSyncMessage(json);
- var obj = JSON.parse(result);
+ var obj = JSON_.parse(result);
if (obj.error)
throw new WebAPIException(obj.code, obj.name, obj.message);
return obj.result;
@@ -1357,7 +1362,7 @@ var NativeBridge = (function (extension, debug) {
async: function (data) {
var l = new Listener();
data.cid = Listeners.getInstance().add(l);
- var json = JSON.stringify({
+ var json = JSON_.stringify({
cmd: data.cmd,
args: data
});
@@ -1395,7 +1400,7 @@ var NativeBridge = (function (extension, debug) {
*/
if (debug) console.log('bridge.setMessageListener, json: ' + json);
- var data = JSON.parse(json);
+ var data = JSON_.parse(json);
if (data.cid && data.action) {
setTimeout(function() {
Listeners.getInstance().resolve(data.cid, data.action, data.args, data.keep);
--
2.7.4
From b49d637448236b92380fa24e8c195056d968822f Mon Sep 17 00:00:00 2001
From: Szymon Jastrzebski
Date: Wed, 12 Apr 2017 10:12:03 +0200
Subject: [PATCH 15/16] [Common] Replacing JS warnings + errors
[Verification] Related TCT result did not change
Change-Id: I32be5db87552997eaa0c173dea29bca13873b5eb
Signed-off-by: Szymon Jastrzebski
---
src/application/application_api.js | 4 +-
src/bluetooth/bluetooth_api.js | 2 +-
src/calendar/js/calendar_alarm.js | 4 +-
src/content/js/manager.js | 5 +-
.../humanactivitymonitor_api.js | 4 +-
src/nfc/nfc_api.js | 2 +-
src/power/power_api.js | 7 ++-
src/push/push_api.js | 10 ++--
src/systeminfo/systeminfo_api.js | 2 +-
src/time/time_api.js | 2 +-
src/utils/utils_api.js | 64 +++++++++++++---------
11 files changed, 62 insertions(+), 44 deletions(-)
diff --git a/src/application/application_api.js b/src/application/application_api.js
index b0d5774..b668dbb 100755
--- a/src/application/application_api.js
+++ b/src/application/application_api.js
@@ -565,7 +565,7 @@ var APPLICATION_EVENT_LISTENER = 'ApplicationEventListener';
var applicationEventListener = new ListenerManager(native, APPLICATION_EVENT_LISTENER);
ApplicationManager.prototype.addAppInfoEventListener = function() {
- console.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. '
+ privUtils_.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. '
+ 'Use tizen.package.setPackageInfoEventListener() instead.');
var args = AV.validateMethod(arguments, [
@@ -580,7 +580,7 @@ ApplicationManager.prototype.addAppInfoEventListener = function() {
};
ApplicationManager.prototype.removeAppInfoEventListener = function() {
- console.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. '
+ privUtils_.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. '
+ 'Use tizen.package.unsetPackageInfoEventListener() instead.');
var args = AV.validateMethod(arguments, [
diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js
index 117ff30..09979b3 100755
--- a/src/bluetooth/bluetooth_api.js
+++ b/src/bluetooth/bluetooth_api.js
@@ -2034,7 +2034,7 @@ BluetoothAdapter.prototype.setName = function() {
BluetoothAdapter.prototype.setPowered = function() {
privUtils_.log('Entered BluetoothAdapter.setPowered()');
- console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. '
+ privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. '
+ 'Let the user turn on/off Bluetooth through the Settings application instead.');
var args = AV.validateMethod(arguments, [
diff --git a/src/calendar/js/calendar_alarm.js b/src/calendar/js/calendar_alarm.js
index 08c2638..6976ac5 100755
--- a/src/calendar/js/calendar_alarm.js
+++ b/src/calendar/js/calendar_alarm.js
@@ -19,6 +19,8 @@ var AlarmMethod = {
DISPLAY: 'DISPLAY'
};
+var privUtils_ = xwalk.utils;
+
var CalendarAlarm = function(time, method, description) {
validator_.isConstructorCall(this, CalendarAlarm);
@@ -30,7 +32,7 @@ var CalendarAlarm = function(time, method, description) {
try {
_method = converter_.toEnum(method, Object.keys(AlarmMethod), false);
} catch (e) {
- console.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.');
+ privUtils_.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.');
_method = method;
}
diff --git a/src/content/js/manager.js b/src/content/js/manager.js
index 6498d59..db388dc 100755
--- a/src/content/js/manager.js
+++ b/src/content/js/manager.js
@@ -15,6 +15,7 @@
*/
var T_ = xwalk.utils.type;
+var privUtils_ = xwalk.utils;
var CONTENT_MANAGER_LISTENER_ID = 'ContentManagerChangeCallback';
@@ -335,7 +336,7 @@ ContentManager.prototype.removeChangeListener = function() {
};
ContentManager.prototype.setChangeListener = function(changeCallback) {
- console.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed '
+ privUtils_.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed '
+ 'from next release. Use addChangeListener() instead.');
var args = validator_.validateArgs(arguments, [{
@@ -370,7 +371,7 @@ ContentManager.prototype.setChangeListener = function(changeCallback) {
};
ContentManager.prototype.unsetChangeListener = function() {
- console.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed '
+ privUtils_.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed '
+ 'from next release. Use removeChangeListener() instead.');
var data = {};
diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js
index 81002eb..3f06004 100755
--- a/src/humanactivitymonitor/humanactivitymonitor_api.js
+++ b/src/humanactivitymonitor/humanactivitymonitor_api.js
@@ -97,7 +97,7 @@ function convertActivityData(type, data) {
case HumanActivityType.SLEEP_MONITOR:
return new HumanActivitySleepMonitorData(data);
default:
- console.error('Uknown human activity type: ' + type);
+ utils_.error('Uknown human activity type: ' + type);
}
}
@@ -127,7 +127,7 @@ function convertActivityRecorderData(type, data) {
func = HumanActivityRecorderPressureData;
break;
default:
- console.error('Uknown human activity recorder type: ' + type);
+ utils_.error('Uknown human activity recorder type: ' + type);
return;
}
diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js
index db3d0e3..8aa8b58 100644
--- a/src/nfc/nfc_api.js
+++ b/src/nfc/nfc_api.js
@@ -272,7 +272,7 @@ function NFCAdapter() {
}
NFCAdapter.prototype.setPowered = function() {
- console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off '
+ privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off '
+ 'through the Settings application instead.');
var args = validator_.validateArgs(arguments, [
diff --git a/src/power/power_api.js b/src/power/power_api.js
index f7a711d..06453eb 100755
--- a/src/power/power_api.js
+++ b/src/power/power_api.js
@@ -18,6 +18,7 @@ var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
+var privUtils_ = xwalk.utils;
function ListenerManager(native, listenerName) {
this.listener;
@@ -127,7 +128,7 @@ PowerManager.prototype.request = function(resource, state) {
]);
if (args['state'] && args.state === PowerScreenState['SCREEN_BRIGHT']) {
- console.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.');
+ privUtils_.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.');
}
var nativeParam = {
@@ -278,7 +279,7 @@ PowerManager.prototype.restoreScreenBrightness = function() {
* Turns on the screen.
*/
PowerManager.prototype.turnScreenOn = function() {
- console.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.');
+ privUtils_.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.');
var nativeParam = {
};
@@ -295,7 +296,7 @@ PowerManager.prototype.turnScreenOn = function() {
* Turns off the screen.
*/
PowerManager.prototype.turnScreenOff = function() {
- console.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.');
+ privUtils_.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.');
var nativeParam = {
};
diff --git a/src/push/push_api.js b/src/push/push_api.js
index 6e623a6..78d4113 100644
--- a/src/push/push_api.js
+++ b/src/push/push_api.js
@@ -17,7 +17,7 @@
var native = new xwalk.utils.NativeManager(extension);
var validator = xwalk.utils.validator;
var validatorType = xwalk.utils.type;
-
+var privUtils_ = xwalk.utils;
/**
* @const
@@ -59,7 +59,7 @@ function PushManager() {
}
PushManager.prototype.registerService = function() {
- console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
+ privUtils_.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'appControl',
@@ -121,7 +121,7 @@ PushManager.prototype.register = function() {
};
PushManager.prototype.unregisterService = function() {
- console.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.');
+ privUtils_.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'successCallback',
@@ -182,7 +182,7 @@ PushManager.prototype.unregister = function() {
};
PushManager.prototype.connectService = function(notificationCallback) {
- console.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.');
+ privUtils_.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'notificationCallback',
@@ -246,7 +246,7 @@ PushManager.prototype.connect = function(notificationCallback) {
};
PushManager.prototype.disconnectService = function() {
- console.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
+ privUtils_.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
var ret = native.callSync('Push_disconnectService', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js
index ce4755b..e09c977 100644
--- a/src/systeminfo/systeminfo_api.js
+++ b/src/systeminfo/systeminfo_api.js
@@ -737,7 +737,7 @@ var SystemInfo = function() {
};
SystemInfo.prototype.getCapabilities = function() {
- console.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.');
+ privUtils_.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.');
var result = native_.callSync('SystemInfo_getCapabilities', {});
if (native_.isFailure(result)) {
diff --git a/src/time/time_api.js b/src/time/time_api.js
index 95c9d6f..ba31ab8 100644
--- a/src/time/time_api.js
+++ b/src/time/time_api.js
@@ -533,7 +533,7 @@ tizen.TZDate.prototype.toString = function() {
tizen.TZDate.prototype.getTimezoneAbbreviation = function() {
utils_.log('Entered TZDate.getTimezoneAbbreviation');
- console.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.');
+ utils_.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.');
var result = native_.callSync('TZDate_getTimezoneAbbreviation',
{timezone: String(this._timezoneName),
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index ca61725..1653b54 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -5,10 +5,16 @@
//Object xwalk.JSON - guaranteed to not being modified by the application programmer
var JSON_ = {stringify: JSON.stringify, parse: JSON.parse};
-Object.freeze(JSON_)
+Object.freeze(JSON_);
exports.JSON = JSON_;
var _enableJsLogs = false;
+var _console = {
+ error: console.error,
+ log: console.log,
+ warn: console.warn
+};
+Object.freeze(_console);
var _global = {};
if (typeof window != 'undefined') {
@@ -146,11 +152,19 @@ function Utils() {
});
}
+Utils.prototype.error = function() {
+ _console.error.apply(_console, arguments);
+};
+
Utils.prototype.log = function() {
if (_enableJsLogs) {
- console.log.apply(console, arguments);
+ _console.log.apply(_console, arguments);
}
-}
+};
+
+Utils.prototype.warn = function() {
+ _console.warn.apply(_console, arguments);
+};
Utils.prototype.repackFilter = function(filter) {
if (filter instanceof tizen.AttributeFilter) {
@@ -975,19 +989,19 @@ var NativeManager = function(extension) {
// TODO: Remove mockup if WRT implements sendRuntimeMessage
// This is temporary mockup!
extension.sendRuntimeMessage = extension.sendRuntimeMessage || function() {
- console.error('Runtime did not implement extension.sendRuntimeMessage!');
+ _console.error('Runtime did not implement extension.sendRuntimeMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeMessage!');
};
extension.sendRuntimeAsyncMessage = extension.sendRuntimeAsyncMessage || function() {
- console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!');
+ _console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeAsyncMessage!');
};
extension.sendRuntimeSyncMessage = extension.sendRuntimeSyncMessage || function() {
- console.error('Runtime did not implement extension.sendRuntimeSyncMessage!');
+ _console.error('Runtime did not implement extension.sendRuntimeSyncMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeSyncMessage!');
};
@@ -1028,7 +1042,7 @@ var NativeManager = function(extension) {
delete msg[this.CALLBACK_ID_KEY];
if (!_type.isFunction(this.callbacks_[id])) {
- console.error('Wrong callback identifier. Ignoring message.');
+ _console.error('Wrong callback identifier. Ignoring message.');
return;
}
@@ -1037,8 +1051,8 @@ var NativeManager = function(extension) {
try {
f(msg);
} catch (e) {
- console.error('########## exception');
- console.error(e);
+ _console.error('########## exception');
+ _console.error(e);
}
}, 0);
delete this.callbacks_[id];
@@ -1051,7 +1065,7 @@ var NativeManager = function(extension) {
delete msg[this.LISTENER_ID_KEY];
if (!_type.isFunction(this.listeners_[id])) {
- console.error('Wrong listener identifier. Ignoring message.');
+ _console.error('Wrong listener identifier. Ignoring message.');
return;
}
@@ -1060,15 +1074,15 @@ var NativeManager = function(extension) {
try {
f(msg);
} catch (e) {
- console.error('########## exception');
- console.error(e);
+ _console.error('########## exception');
+ _console.error(e);
}
}, 0);
return;
}
- console.error('Missing callback or listener identifier. Ignoring message.');
+ _console.error('Missing callback or listener identifier. Ignoring message.');
}.bind(this));
};
@@ -1174,7 +1188,7 @@ NativeManager.prototype.callIfPossible = function(callback) {
* age: 28
* }
* });
- * console.log(result);
+ * _console.log(result);
*
* To send async method and handle response:
* bridge.async({
@@ -1229,7 +1243,7 @@ var NativeBridge = (function (extension, debug) {
CallbackManager.prototype = {
add: function (/*callbacks, cid?*/) {
- if (debug) console.log('bridge.CallbackManager.add');
+ if (debug) _console.log('bridge.CallbackManager.add');
var args = Array.prototype.slice.call(arguments);
var c = args.shift();
var cid = args.pop();
@@ -1246,11 +1260,11 @@ var NativeBridge = (function (extension, debug) {
return cid;
},
remove: function (cid) {
- if (debug) console.log('bridge.CallbackManager.remove, cid: ' + cid);
+ if (debug) _console.log('bridge.CallbackManager.remove, cid: ' + cid);
if (_collection[cid]) delete _collection[cid];
},
call: function (cid, key, args, keep) {
- if (debug) console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
+ if (debug) _console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
var callbacks = _collection[cid];
keep = !!keep;
if (callbacks) {
@@ -1282,13 +1296,13 @@ var NativeBridge = (function (extension, debug) {
ListenerManager.prototype = {
add: function (l) {
- if (debug) console.log('bridge.ListenerManager.add');
+ if (debug) _console.log('bridge.ListenerManager.add');
var id = _next();
_listeners[id] = l;
return id;
},
resolve: function (id, action, data, keep) {
- if (debug) console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
+ if (debug) _console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
keep = !!keep;
var l = _listeners[id];
if (l) {
@@ -1298,7 +1312,7 @@ var NativeBridge = (function (extension, debug) {
return l;
},
remove: function (id) {
- if (debug) console.log('bridge.ListenerManager.remove, id: ' + id);
+ if (debug) _console.log('bridge.ListenerManager.remove, id: ' + id);
var l = _listeners[id];
if (l) {
var cm = Callbacks.getInstance();
@@ -1333,12 +1347,12 @@ var NativeBridge = (function (extension, debug) {
})();
var Listener = function () {
- if (debug) console.log('bridge: Listener constructor');
+ if (debug) _console.log('bridge: Listener constructor');
this.cid = null;
};
Listener.prototype = {
then: function (c) {
- if (debug) console.log('bridge.Listener.then');
+ if (debug) _console.log('bridge.Listener.then');
var cm = Callbacks.getInstance();
this.cid = cm.add(c, this.cid);
return this;
@@ -1352,7 +1366,7 @@ var NativeBridge = (function (extension, debug) {
cmd: data.cmd,
args: data
});
- if (debug) console.log('bridge.sync, json: ' + json);
+ if (debug) _console.log('bridge.sync, json: ' + json);
var result = extension.internal.sendSyncMessage(json);
var obj = JSON_.parse(result);
if (obj.error)
@@ -1366,7 +1380,7 @@ var NativeBridge = (function (extension, debug) {
cmd: data.cmd,
args: data
});
- if (debug) console.log('bridge.async, json: ' + json);
+ if (debug) _console.log('bridge.async, json: ' + json);
setTimeout(function () {
extension.postMessage(json);
});
@@ -1399,7 +1413,7 @@ var NativeBridge = (function (extension, debug) {
*}
*/
- if (debug) console.log('bridge.setMessageListener, json: ' + json);
+ if (debug) _console.log('bridge.setMessageListener, json: ' + json);
var data = JSON_.parse(json);
if (data.cid && data.action) {
setTimeout(function() {
--
2.7.4
From 3ccbc72dbbced354cc945e3041c2c5d109781cad Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Wed, 12 Apr 2017 03:27:15 -0700
Subject: [PATCH 16/16] Revert "[Common] Replacing JS warnings + errors"
This reverts commit b49d637448236b92380fa24e8c195056d968822f.
Change-Id: Ia92ed37fbdc45e43ef2ad2eb74bc67cc10244f7f
---
src/application/application_api.js | 4 +-
src/bluetooth/bluetooth_api.js | 2 +-
src/calendar/js/calendar_alarm.js | 4 +-
src/content/js/manager.js | 5 +-
.../humanactivitymonitor_api.js | 4 +-
src/nfc/nfc_api.js | 2 +-
src/power/power_api.js | 7 +--
src/push/push_api.js | 10 ++--
src/systeminfo/systeminfo_api.js | 2 +-
src/time/time_api.js | 2 +-
src/utils/utils_api.js | 64 +++++++++-------------
11 files changed, 44 insertions(+), 62 deletions(-)
diff --git a/src/application/application_api.js b/src/application/application_api.js
index b668dbb..b0d5774 100755
--- a/src/application/application_api.js
+++ b/src/application/application_api.js
@@ -565,7 +565,7 @@ var APPLICATION_EVENT_LISTENER = 'ApplicationEventListener';
var applicationEventListener = new ListenerManager(native, APPLICATION_EVENT_LISTENER);
ApplicationManager.prototype.addAppInfoEventListener = function() {
- privUtils_.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. '
+ console.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. '
+ 'Use tizen.package.setPackageInfoEventListener() instead.');
var args = AV.validateMethod(arguments, [
@@ -580,7 +580,7 @@ ApplicationManager.prototype.addAppInfoEventListener = function() {
};
ApplicationManager.prototype.removeAppInfoEventListener = function() {
- privUtils_.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. '
+ console.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. '
+ 'Use tizen.package.unsetPackageInfoEventListener() instead.');
var args = AV.validateMethod(arguments, [
diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js
index 09979b3..117ff30 100755
--- a/src/bluetooth/bluetooth_api.js
+++ b/src/bluetooth/bluetooth_api.js
@@ -2034,7 +2034,7 @@ BluetoothAdapter.prototype.setName = function() {
BluetoothAdapter.prototype.setPowered = function() {
privUtils_.log('Entered BluetoothAdapter.setPowered()');
- privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. '
+ console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. '
+ 'Let the user turn on/off Bluetooth through the Settings application instead.');
var args = AV.validateMethod(arguments, [
diff --git a/src/calendar/js/calendar_alarm.js b/src/calendar/js/calendar_alarm.js
index 6976ac5..08c2638 100755
--- a/src/calendar/js/calendar_alarm.js
+++ b/src/calendar/js/calendar_alarm.js
@@ -19,8 +19,6 @@ var AlarmMethod = {
DISPLAY: 'DISPLAY'
};
-var privUtils_ = xwalk.utils;
-
var CalendarAlarm = function(time, method, description) {
validator_.isConstructorCall(this, CalendarAlarm);
@@ -32,7 +30,7 @@ var CalendarAlarm = function(time, method, description) {
try {
_method = converter_.toEnum(method, Object.keys(AlarmMethod), false);
} catch (e) {
- privUtils_.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.');
+ console.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.');
_method = method;
}
diff --git a/src/content/js/manager.js b/src/content/js/manager.js
index db388dc..6498d59 100755
--- a/src/content/js/manager.js
+++ b/src/content/js/manager.js
@@ -15,7 +15,6 @@
*/
var T_ = xwalk.utils.type;
-var privUtils_ = xwalk.utils;
var CONTENT_MANAGER_LISTENER_ID = 'ContentManagerChangeCallback';
@@ -336,7 +335,7 @@ ContentManager.prototype.removeChangeListener = function() {
};
ContentManager.prototype.setChangeListener = function(changeCallback) {
- privUtils_.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed '
+ console.warn('DEPRECATION WARNING: setChangeListener() is deprecated and will be removed '
+ 'from next release. Use addChangeListener() instead.');
var args = validator_.validateArgs(arguments, [{
@@ -371,7 +370,7 @@ ContentManager.prototype.setChangeListener = function(changeCallback) {
};
ContentManager.prototype.unsetChangeListener = function() {
- privUtils_.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed '
+ console.warn('DEPRECATION WARNING: unsetChangeListener() is deprecated and will be removed '
+ 'from next release. Use removeChangeListener() instead.');
var data = {};
diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js
index 3f06004..81002eb 100755
--- a/src/humanactivitymonitor/humanactivitymonitor_api.js
+++ b/src/humanactivitymonitor/humanactivitymonitor_api.js
@@ -97,7 +97,7 @@ function convertActivityData(type, data) {
case HumanActivityType.SLEEP_MONITOR:
return new HumanActivitySleepMonitorData(data);
default:
- utils_.error('Uknown human activity type: ' + type);
+ console.error('Uknown human activity type: ' + type);
}
}
@@ -127,7 +127,7 @@ function convertActivityRecorderData(type, data) {
func = HumanActivityRecorderPressureData;
break;
default:
- utils_.error('Uknown human activity recorder type: ' + type);
+ console.error('Uknown human activity recorder type: ' + type);
return;
}
diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js
index 8aa8b58..db3d0e3 100644
--- a/src/nfc/nfc_api.js
+++ b/src/nfc/nfc_api.js
@@ -272,7 +272,7 @@ function NFCAdapter() {
}
NFCAdapter.prototype.setPowered = function() {
- privUtils_.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off '
+ console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off '
+ 'through the Settings application instead.');
var args = validator_.validateArgs(arguments, [
diff --git a/src/power/power_api.js b/src/power/power_api.js
index 06453eb..f7a711d 100755
--- a/src/power/power_api.js
+++ b/src/power/power_api.js
@@ -18,7 +18,6 @@ var JSON_ = xwalk.JSON;
var validator_ = xwalk.utils.validator;
var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
-var privUtils_ = xwalk.utils;
function ListenerManager(native, listenerName) {
this.listener;
@@ -128,7 +127,7 @@ PowerManager.prototype.request = function(resource, state) {
]);
if (args['state'] && args.state === PowerScreenState['SCREEN_BRIGHT']) {
- privUtils_.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.');
+ console.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.');
}
var nativeParam = {
@@ -279,7 +278,7 @@ PowerManager.prototype.restoreScreenBrightness = function() {
* Turns on the screen.
*/
PowerManager.prototype.turnScreenOn = function() {
- privUtils_.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.');
+ console.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.');
var nativeParam = {
};
@@ -296,7 +295,7 @@ PowerManager.prototype.turnScreenOn = function() {
* Turns off the screen.
*/
PowerManager.prototype.turnScreenOff = function() {
- privUtils_.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.');
+ console.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.');
var nativeParam = {
};
diff --git a/src/push/push_api.js b/src/push/push_api.js
index 78d4113..6e623a6 100644
--- a/src/push/push_api.js
+++ b/src/push/push_api.js
@@ -17,7 +17,7 @@
var native = new xwalk.utils.NativeManager(extension);
var validator = xwalk.utils.validator;
var validatorType = xwalk.utils.type;
-var privUtils_ = xwalk.utils;
+
/**
* @const
@@ -59,7 +59,7 @@ function PushManager() {
}
PushManager.prototype.registerService = function() {
- privUtils_.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
+ console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'appControl',
@@ -121,7 +121,7 @@ PushManager.prototype.register = function() {
};
PushManager.prototype.unregisterService = function() {
- privUtils_.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.');
+ console.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'successCallback',
@@ -182,7 +182,7 @@ PushManager.prototype.unregister = function() {
};
PushManager.prototype.connectService = function(notificationCallback) {
- privUtils_.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.');
+ console.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'notificationCallback',
@@ -246,7 +246,7 @@ PushManager.prototype.connect = function(notificationCallback) {
};
PushManager.prototype.disconnectService = function() {
- privUtils_.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
+ console.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
var ret = native.callSync('Push_disconnectService', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js
index e09c977..ce4755b 100644
--- a/src/systeminfo/systeminfo_api.js
+++ b/src/systeminfo/systeminfo_api.js
@@ -737,7 +737,7 @@ var SystemInfo = function() {
};
SystemInfo.prototype.getCapabilities = function() {
- privUtils_.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.');
+ console.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.');
var result = native_.callSync('SystemInfo_getCapabilities', {});
if (native_.isFailure(result)) {
diff --git a/src/time/time_api.js b/src/time/time_api.js
index ba31ab8..95c9d6f 100644
--- a/src/time/time_api.js
+++ b/src/time/time_api.js
@@ -533,7 +533,7 @@ tizen.TZDate.prototype.toString = function() {
tizen.TZDate.prototype.getTimezoneAbbreviation = function() {
utils_.log('Entered TZDate.getTimezoneAbbreviation');
- utils_.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.');
+ console.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.');
var result = native_.callSync('TZDate_getTimezoneAbbreviation',
{timezone: String(this._timezoneName),
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index 1653b54..ca61725 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -5,16 +5,10 @@
//Object xwalk.JSON - guaranteed to not being modified by the application programmer
var JSON_ = {stringify: JSON.stringify, parse: JSON.parse};
-Object.freeze(JSON_);
+Object.freeze(JSON_)
exports.JSON = JSON_;
var _enableJsLogs = false;
-var _console = {
- error: console.error,
- log: console.log,
- warn: console.warn
-};
-Object.freeze(_console);
var _global = {};
if (typeof window != 'undefined') {
@@ -152,19 +146,11 @@ function Utils() {
});
}
-Utils.prototype.error = function() {
- _console.error.apply(_console, arguments);
-};
-
Utils.prototype.log = function() {
if (_enableJsLogs) {
- _console.log.apply(_console, arguments);
+ console.log.apply(console, arguments);
}
-};
-
-Utils.prototype.warn = function() {
- _console.warn.apply(_console, arguments);
-};
+}
Utils.prototype.repackFilter = function(filter) {
if (filter instanceof tizen.AttributeFilter) {
@@ -989,19 +975,19 @@ var NativeManager = function(extension) {
// TODO: Remove mockup if WRT implements sendRuntimeMessage
// This is temporary mockup!
extension.sendRuntimeMessage = extension.sendRuntimeMessage || function() {
- _console.error('Runtime did not implement extension.sendRuntimeMessage!');
+ console.error('Runtime did not implement extension.sendRuntimeMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeMessage!');
};
extension.sendRuntimeAsyncMessage = extension.sendRuntimeAsyncMessage || function() {
- _console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!');
+ console.error('Runtime did not implement extension.sendRuntimeAsyncMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeAsyncMessage!');
};
extension.sendRuntimeSyncMessage = extension.sendRuntimeSyncMessage || function() {
- _console.error('Runtime did not implement extension.sendRuntimeSyncMessage!');
+ console.error('Runtime did not implement extension.sendRuntimeSyncMessage!');
throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
'Runtime did not implement extension.sendRuntimeSyncMessage!');
};
@@ -1042,7 +1028,7 @@ var NativeManager = function(extension) {
delete msg[this.CALLBACK_ID_KEY];
if (!_type.isFunction(this.callbacks_[id])) {
- _console.error('Wrong callback identifier. Ignoring message.');
+ console.error('Wrong callback identifier. Ignoring message.');
return;
}
@@ -1051,8 +1037,8 @@ var NativeManager = function(extension) {
try {
f(msg);
} catch (e) {
- _console.error('########## exception');
- _console.error(e);
+ console.error('########## exception');
+ console.error(e);
}
}, 0);
delete this.callbacks_[id];
@@ -1065,7 +1051,7 @@ var NativeManager = function(extension) {
delete msg[this.LISTENER_ID_KEY];
if (!_type.isFunction(this.listeners_[id])) {
- _console.error('Wrong listener identifier. Ignoring message.');
+ console.error('Wrong listener identifier. Ignoring message.');
return;
}
@@ -1074,15 +1060,15 @@ var NativeManager = function(extension) {
try {
f(msg);
} catch (e) {
- _console.error('########## exception');
- _console.error(e);
+ console.error('########## exception');
+ console.error(e);
}
}, 0);
return;
}
- _console.error('Missing callback or listener identifier. Ignoring message.');
+ console.error('Missing callback or listener identifier. Ignoring message.');
}.bind(this));
};
@@ -1188,7 +1174,7 @@ NativeManager.prototype.callIfPossible = function(callback) {
* age: 28
* }
* });
- * _console.log(result);
+ * console.log(result);
*
* To send async method and handle response:
* bridge.async({
@@ -1243,7 +1229,7 @@ var NativeBridge = (function (extension, debug) {
CallbackManager.prototype = {
add: function (/*callbacks, cid?*/) {
- if (debug) _console.log('bridge.CallbackManager.add');
+ if (debug) console.log('bridge.CallbackManager.add');
var args = Array.prototype.slice.call(arguments);
var c = args.shift();
var cid = args.pop();
@@ -1260,11 +1246,11 @@ var NativeBridge = (function (extension, debug) {
return cid;
},
remove: function (cid) {
- if (debug) _console.log('bridge.CallbackManager.remove, cid: ' + cid);
+ if (debug) console.log('bridge.CallbackManager.remove, cid: ' + cid);
if (_collection[cid]) delete _collection[cid];
},
call: function (cid, key, args, keep) {
- if (debug) _console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
+ if (debug) console.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
var callbacks = _collection[cid];
keep = !!keep;
if (callbacks) {
@@ -1296,13 +1282,13 @@ var NativeBridge = (function (extension, debug) {
ListenerManager.prototype = {
add: function (l) {
- if (debug) _console.log('bridge.ListenerManager.add');
+ if (debug) console.log('bridge.ListenerManager.add');
var id = _next();
_listeners[id] = l;
return id;
},
resolve: function (id, action, data, keep) {
- if (debug) _console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
+ if (debug) console.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
keep = !!keep;
var l = _listeners[id];
if (l) {
@@ -1312,7 +1298,7 @@ var NativeBridge = (function (extension, debug) {
return l;
},
remove: function (id) {
- if (debug) _console.log('bridge.ListenerManager.remove, id: ' + id);
+ if (debug) console.log('bridge.ListenerManager.remove, id: ' + id);
var l = _listeners[id];
if (l) {
var cm = Callbacks.getInstance();
@@ -1347,12 +1333,12 @@ var NativeBridge = (function (extension, debug) {
})();
var Listener = function () {
- if (debug) _console.log('bridge: Listener constructor');
+ if (debug) console.log('bridge: Listener constructor');
this.cid = null;
};
Listener.prototype = {
then: function (c) {
- if (debug) _console.log('bridge.Listener.then');
+ if (debug) console.log('bridge.Listener.then');
var cm = Callbacks.getInstance();
this.cid = cm.add(c, this.cid);
return this;
@@ -1366,7 +1352,7 @@ var NativeBridge = (function (extension, debug) {
cmd: data.cmd,
args: data
});
- if (debug) _console.log('bridge.sync, json: ' + json);
+ if (debug) console.log('bridge.sync, json: ' + json);
var result = extension.internal.sendSyncMessage(json);
var obj = JSON_.parse(result);
if (obj.error)
@@ -1380,7 +1366,7 @@ var NativeBridge = (function (extension, debug) {
cmd: data.cmd,
args: data
});
- if (debug) _console.log('bridge.async, json: ' + json);
+ if (debug) console.log('bridge.async, json: ' + json);
setTimeout(function () {
extension.postMessage(json);
});
@@ -1413,7 +1399,7 @@ var NativeBridge = (function (extension, debug) {
*}
*/
- if (debug) _console.log('bridge.setMessageListener, json: ' + json);
+ if (debug) console.log('bridge.setMessageListener, json: ' + json);
var data = JSON_.parse(json);
if (data.cid && data.action) {
setTimeout(function() {
--
2.7.4