summaryrefslogtreecommitdiff
path: root/src/components/policy
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy')
-rw-r--r--src/components/policy/policy_external/doc/doxygen/tools/InterfaceGenerator/How To Use.txt2
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h2
-rw-r--r--src/components/policy/policy_external/include/policy/update_status_manager.h2
-rw-r--r--src/components/policy/policy_external/src/cache_manager.cc21
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc20
-rw-r--r--src/components/policy/policy_external/src/status.cc3
-rw-r--r--src/components/policy/policy_external/src/update_status_manager.cc6
-rw-r--r--src/components/policy/policy_external/test/generated_code_test.cc10
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc21
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc8
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_test.cc5
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_test_base.cc34
-rw-r--r--src/components/policy/policy_external/test/sql_pt_representation_test.cc12
-rw-r--r--src/components/policy/policy_external/test/update_status_manager_test.cc6
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h2
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc20
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc26
-rw-r--r--src/components/policy/policy_regular/test/generated_code_test.cc10
-rw-r--r--src/components/policy/policy_regular/test/policy_manager_impl_test.cc50
-rw-r--r--src/components/policy/policy_regular/test/sql_pt_representation_test.cc6
-rw-r--r--src/components/policy/policy_regular/test/vehicle_data_item_type_test.cc30
21 files changed, 185 insertions, 111 deletions
diff --git a/src/components/policy/policy_external/doc/doxygen/tools/InterfaceGenerator/How To Use.txt b/src/components/policy/policy_external/doc/doxygen/tools/InterfaceGenerator/How To Use.txt
index 0f9e340bc5..e7b14b0da1 100644
--- a/src/components/policy/policy_external/doc/doxygen/tools/InterfaceGenerator/How To Use.txt
+++ b/src/components/policy/policy_external/doc/doxygen/tools/InterfaceGenerator/How To Use.txt
@@ -1,6 +1,6 @@
/*! \page tools_interfacegenerator_usage How to use InterfaceGenerator
-To run InterfaceGenerator the Python 2.7 interpreter should be installed. As input InterfaceGenerator requires full path to the source XML file, namespace to generate result code in, full path to the output directory where result source code C++ will be created and optionally explicit specification of parser type.
+To run InterfaceGenerator the Python 3.5+ interpreter should be installed. As input InterfaceGenerator requires full path to the source XML file, namespace to generate result code in, full path to the output directory where result source code C++ will be created and optionally explicit specification of parser type.
Example1 (Run Generator.py to display help):
diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
index b1c22ab9e6..ce344d576a 100644
--- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
@@ -1139,6 +1139,8 @@ class PolicyManagerImpl : public PolicyManager {
bool GetModuleTypes(const std::string& policy_app_id,
std::vector<std::string>* modules) const OVERRIDE;
+ void ResetTimeout() OVERRIDE;
+
/**
* @brief Notify application about its permissions changes by preparing and
* sending OnPermissionsChanged notification
diff --git a/src/components/policy/policy_external/include/policy/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h
index c5738b3272..9426a26fb8 100644
--- a/src/components/policy/policy_external/include/policy/update_status_manager.h
+++ b/src/components/policy/policy_external/include/policy/update_status_manager.h
@@ -185,6 +185,8 @@ class UpdateStatusManager {
*/
bool IsAppsSearchInProgress();
+ void ResetTimeout(uint32_t update_timeout);
+
#ifdef BUILD_TESTS
PolicyTableStatus GetLastUpdateStatus() const {
return current_status_->get_status();
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc
index c9ed786509..5bf4bfd658 100644
--- a/src/components/policy/policy_external/src/cache_manager.cc
+++ b/src/components/policy/policy_external/src/cache_manager.cc
@@ -41,8 +41,6 @@
#include <utility>
#include <vector>
-#include "json/features.h"
-#include "json/reader.h"
#include "json/writer.h"
#include "policy/policy_helper.h"
#include "policy/policy_table/enums.h"
@@ -52,6 +50,7 @@
#include "utils/file_system.h"
#include "utils/gen_hash.h"
#include "utils/helpers.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include "utils/logger.h"
#include "utils/threads/thread.h"
#include "utils/threads/thread_delegate.h"
@@ -2703,13 +2702,13 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
LOG4CXX_FATAL(logger_, "Failed to read policy table source file.");
return false;
}
+
+ utils::JsonReader reader;
Json::Value value;
- Json::Reader reader(Json::Features::strictMode());
+
std::string json(json_string.begin(), json_string.end());
- if (!reader.parse(json.c_str(), value)) {
- LOG4CXX_FATAL(
- logger_,
- "Preloaded PT is corrupted: " << reader.getFormattedErrorMessages());
+ if (!reader.parse(json, &value)) {
+ LOG4CXX_FATAL(logger_, "Preloaded PT is corrupted.");
return false;
}
@@ -2720,10 +2719,10 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
table = policy_table::Table(&value);
#ifdef ENABLE_LOG
- Json::StyledWriter s_writer;
- LOG4CXX_DEBUG(
- logger_,
- "Policy table content loaded:" << s_writer.write(table.ToJsonValue()));
+ Json::StreamWriterBuilder writer_builder;
+ LOG4CXX_DEBUG(logger_,
+ "Policy table content loaded:" << Json::writeString(
+ writer_builder, table.ToJsonValue()));
#endif // ENABLE_LOG
MakeLowerCaseAppNames(table);
diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc
index 152a94b963..787e65f43a 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -39,7 +39,6 @@
#include <set>
#include <vector>
#include "config_profile/profile.h"
-#include "json/reader.h"
#include "json/writer.h"
#include "policy/cache_manager.h"
#include "policy/policy_helper.h"
@@ -48,6 +47,7 @@
#include "policy/update_status_manager.h"
#include "utils/date_time.h"
#include "utils/file_system.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include "utils/logger.h"
#include "policy/access_remote.h"
@@ -238,9 +238,10 @@ void PolicyManagerImpl::set_listener(PolicyListener* listener) {
std::shared_ptr<policy_table::Table> PolicyManagerImpl::Parse(
const BinaryMessage& pt_content) {
std::string json(pt_content.begin(), pt_content.end());
+ utils::JsonReader reader;
Json::Value value;
- Json::Reader reader;
- if (reader.parse(json.c_str(), value)) {
+
+ if (reader.parse(json, &value)) {
return std::make_shared<policy_table::Table>(&value);
} else {
return std::make_shared<policy_table::Table>();
@@ -702,8 +703,8 @@ void PolicyManagerImpl::RequestPTUpdate() {
if (IsPTValid(policy_table_snapshot, policy_table::PT_SNAPSHOT)) {
Json::Value value = policy_table_snapshot->ToJsonValue();
- Json::FastWriter writer;
- std::string message_string = writer.write(value);
+ Json::StreamWriterBuilder writer_builder;
+ std::string message_string = Json::writeString(writer_builder, value);
LOG4CXX_DEBUG(logger_, "Snapshot contents is : " << message_string);
@@ -1383,9 +1384,16 @@ void PolicyManagerImpl::RetrySequenceFailed() {
ResetRetrySequence(ResetRetryCountType::kResetWithStatusUpdate);
}
-void PolicyManagerImpl::OnSystemRequestReceived() {
+void PolicyManagerImpl::ResetTimeout() {
LOG4CXX_AUTO_TRACE(logger_);
+ if (update_status_manager_.IsUpdatePending()) {
+ uint32_t update_timeout = TimeoutExchangeMSec();
+ update_status_manager_.ResetTimeout(update_timeout);
+ }
+}
+void PolicyManagerImpl::OnSystemRequestReceived() {
+ LOG4CXX_AUTO_TRACE(logger_);
IncrementRetryIndex();
}
diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc
index 7162410731..687bea1c3f 100644
--- a/src/components/policy/policy_external/src/status.cc
+++ b/src/components/policy/policy_external/src/status.cc
@@ -67,6 +67,9 @@ void policy::UpdateNeededStatus::ProcessEvent(
case kOnResetPolicyTableNoUpdate:
manager->SetNextStatus(std::make_shared<UpToDateStatus>());
break;
+ case kOnNewAppRegistered:
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
+ break;
case kPendingUpdate:
manager->SetNextStatus(std::make_shared<UpdatePendingStatus>());
break;
diff --git a/src/components/policy/policy_external/src/update_status_manager.cc b/src/components/policy/policy_external/src/update_status_manager.cc
index bf20f9dd55..3653983c8f 100644
--- a/src/components/policy/policy_external/src/update_status_manager.cc
+++ b/src/components/policy/policy_external/src/update_status_manager.cc
@@ -108,6 +108,12 @@ void UpdateStatusManager::OnValidUpdateReceived() {
ProcessEvent(kOnValidUpdateReceived);
}
+void UpdateStatusManager::ResetTimeout(uint32_t update_timeout) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ update_status_thread_delegate_->updateTimeOut(
+ update_timeout); // Restart Timer
+}
+
void UpdateStatusManager::OnWrongUpdateReceived() {
LOG4CXX_AUTO_TRACE(logger_);
update_status_thread_delegate_->updateTimeOut(0); // Stop Timer
diff --git a/src/components/policy/policy_external/test/generated_code_test.cc b/src/components/policy/policy_external/test/generated_code_test.cc
index 15d14e3e3b..03cfae511b 100644
--- a/src/components/policy/policy_external/test/generated_code_test.cc
+++ b/src/components/policy/policy_external/test/generated_code_test.cc
@@ -51,8 +51,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTPreloadJsonIsValid) {
std::ifstream json_file("json/sdl_preloaded_pt.json");
ASSERT_TRUE(json_file.is_open());
Json::Value valid_table;
- Json::Reader reader;
- ASSERT_TRUE(reader.parse(json_file, valid_table));
+ Json::CharReaderBuilder reader_builder;
+ ASSERT_TRUE(
+ Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr));
Table table(&valid_table);
table.SetPolicyTableType(rpc::policy_table_interface_base::PT_PRELOADED);
ASSERT_RPCTYPE_VALID(table);
@@ -62,8 +63,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTUpdateJsonIsValid) {
std::ifstream json_file("json/valid_sdl_pt_update.json");
ASSERT_TRUE(json_file.is_open());
Json::Value valid_table;
- Json::Reader reader;
- ASSERT_TRUE(reader.parse(json_file, valid_table));
+ Json::CharReaderBuilder reader_builder;
+ ASSERT_TRUE(
+ Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr));
Table table(&valid_table);
table.SetPolicyTableType(rpc::policy_table_interface_base::PT_UPDATE);
ASSERT_RPCTYPE_VALID(table);
diff --git a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc
index 333f4e8f84..4fbbeaa6aa 100644
--- a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc
+++ b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc
@@ -153,11 +153,11 @@ TEST_F(PolicyManagerImplTest2, IsAppRevoked_SetRevokedAppID_ExpectAppRevoked) {
device_id_1_, app_id_1_, HmiTypes(policy_table::AHT_DEFAULT));
std::ifstream ifile(kValidSdlPtUpdateJson);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
if (ifile.is_open()) {
- if (reader.parse(ifile, root, true)) {
+ if (Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
root["policy_table"]["app_policies"][app_id_1_] = Json::nullValue;
json = root.toStyledString();
}
@@ -249,11 +249,11 @@ TEST_F(PolicyManagerImplTest2,
ASSERT_TRUE(output.list_of_allowed_params.empty());
// Act
std::ifstream ifile(kValidSdlPtUpdateJson);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
EXPECT_TRUE(ifile.is_open());
- EXPECT_TRUE(reader.parse(ifile, root, true));
+ EXPECT_TRUE(Json::parseFromStream(reader_builder, ifile, &root, nullptr));
root["policy_table"]["app_policies"][app_id_1_] = Json::nullValue;
json = root.toStyledString();
ifile.close();
@@ -297,10 +297,11 @@ TEST_F(PolicyManagerImplTest2,
device_id_1_, application_id_, HmiTypes(policy_table::AHT_MEDIA));
// Emulate PTU with new policies for app added above
std::ifstream ifile(kValidSdlPtUpdateJson);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
// Add AppID with policies
root["policy_table"]["app_policies"][application_id_] =
Json::Value(Json::objectValue);
@@ -801,11 +802,11 @@ TEST_F(PolicyManagerImplTest2,
device_id_1_, application_id_, HmiTypes(policy_table::AHT_DEFAULT));
std::ifstream ifile("json/sdl_update_pt_2_groups_no_params_in1.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
if (ifile.is_open()) {
- reader.parse(ifile, root, true);
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr);
}
json = root.toStyledString();
ifile.close();
@@ -903,11 +904,11 @@ TEST_F(PolicyManagerImplTest2,
std::ifstream ifile(
"json/sdl_update_pt_2_groups_no_params_in1_omitted_in2.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
if (ifile.is_open()) {
- reader.parse(ifile, root, true);
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr);
}
json = root.toStyledString();
ifile.close();
diff --git a/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc
index ddb5474df3..f89a2ce0c7 100644
--- a/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc
+++ b/src/components/policy/policy_external/test/policy_manager_impl_snapshot_test.cc
@@ -53,10 +53,11 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) {
CreateLocalPT(preloaded_pt_filename_);
// Update preloadedPT
std::ifstream ifile(preloaded_pt_filename_);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
root["policy_table"]["module_config"]["preloaded_date"] =
new_data.new_date_;
Json::Value val(Json::objectValue);
@@ -70,9 +71,8 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) {
}
ifile.close();
- Json::StyledStreamWriter writer;
std::ofstream ofile(preloaded_pt_filename_);
- writer.write(ofile, root);
+ ofile << root;
ofile.flush();
ofile.close();
diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_test.cc
index 809c0b5599..f824d37dfb 100644
--- a/src/components/policy/policy_external/test/policy_manager_impl_test.cc
+++ b/src/components/policy/policy_external/test/policy_manager_impl_test.cc
@@ -265,9 +265,10 @@ TEST_F(PolicyManagerImplTest2,
RetrySequenceDelaysSeconds_Expect_CorrectValues) {
// Arrange
std::ifstream ifile(preloaded_pt_filename_);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
Json::Value seconds_between_retries = Json::Value(Json::arrayValue);
seconds_between_retries =
root["policy_table"]["module_config"]["seconds_between_retries"];
diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc
index b3c85df65b..9f363a223a 100644
--- a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc
+++ b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc
@@ -39,8 +39,8 @@
#include "utils/file_system.h"
-#include "json/reader.h"
#include "utils/gen_hash.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include "policy/mock_pt_ext_representation.h"
@@ -175,8 +175,8 @@ Json::Value createPTforLoad() {
"}");
Json::Value table(Json::objectValue);
- Json::Reader reader;
- EXPECT_TRUE(reader.parse(load_table, table));
+ utils::JsonReader reader;
+ EXPECT_TRUE(reader.parse(load_table, &table));
return table;
}
@@ -282,10 +282,11 @@ void PolicyManagerImplTest2::SetUp() {
const Json::Value PolicyManagerImplTest2::GetPTU(const std::string& file_name) {
// Get PTU
std::ifstream ifile(file_name);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
json = root.toStyledString();
}
ifile.close();
@@ -471,11 +472,11 @@ void PolicyManagerImplTest2::
// Expect all parameters are allowed
std::ifstream ifile(update_file);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
if (ifile.is_open()) {
- reader.parse(ifile, root, true);
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr);
}
json = root.toStyledString();
ifile.close();
@@ -578,10 +579,11 @@ void PolicyManagerImplTest2::CheckRpcPermissions(
void PolicyManagerImplTest2::EmulatePTAppRevoked(const std::string& ptu_name) {
std::ifstream ifile(ptu_name);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
// Emulate application is revoked
root["policy_table"]["app_policies"]["1234"]["is_revoked"] = 1;
json = root.toStyledString();
@@ -620,11 +622,11 @@ void PolicyManagerImplTest2::LoadPTUFromJsonFile(
const std::string& update_file) {
// Load Json to cache
std::ifstream ifile(update_file);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
if (ifile.is_open()) {
- reader.parse(ifile, root, true);
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr);
}
json = root.toStyledString();
ifile.close();
@@ -684,10 +686,11 @@ const Json::Value PolicyManagerImplTest_RequestTypes::GetPTU(
const std::string& file_name) {
// Get PTU
std::ifstream ifile(file_name);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
json = root.toStyledString();
}
ifile.close();
@@ -905,10 +908,11 @@ std::string PolicyManagerImplTest_ExternalConsent::PreparePTUWithNewGroup(
using namespace rpc;
std::ifstream ifile(preloaded_pt_filename_);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
Table t = PreparePTWithGroupsHavingExternalConsent();
ExternalConsentEntity entity_4(type, id);
diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc
index 67702ab4d2..2f85f8dc0a 100644
--- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc
+++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc
@@ -1682,13 +1682,15 @@ TEST_F(SQLPTRepresentationTest,
table["policy_table"]["module_meta"] = Json::Value(Json::objectValue);
table["policy_table"]["module_config"]["preloaded_pt"] = Json::Value(false);
policy_table::Table expected(&table);
- Json::StyledWriter writer;
+ Json::StreamWriterBuilder writer_builder;
// Checks
- EXPECT_EQ(writer.write(expected.ToJsonValue()),
- writer.write(snapshot->ToJsonValue()));
- std::cout << writer.write(snapshot->ToJsonValue()) << std::endl;
+ Json::Value snapshot_json_value = snapshot->ToJsonValue();
+ EXPECT_EQ(Json::writeString(writer_builder, expected.ToJsonValue()),
+ Json::writeString(writer_builder, snapshot_json_value));
+ std::cout << Json::writeString(writer_builder, snapshot_json_value)
+ << std::endl;
EXPECT_EQ(expected.ToJsonValue().toStyledString(),
- snapshot->ToJsonValue().toStyledString());
+ snapshot_json_value.toStyledString());
}
TEST_F(SQLPTRepresentationTest,
diff --git a/src/components/policy/policy_external/test/update_status_manager_test.cc b/src/components/policy/policy_external/test/update_status_manager_test.cc
index 9f68456750..29952bd18e 100644
--- a/src/components/policy/policy_external/test/update_status_manager_test.cc
+++ b/src/components/policy/policy_external/test/update_status_manager_test.cc
@@ -340,6 +340,12 @@ TEST_F(UpdateStatusManagerTest,
EXPECT_FALSE(manager_->IsAppsSearchInProgress());
}
+TEST_F(UpdateStatusManagerTest, OnAppRegistered) {
+ manager_->ScheduleUpdate();
+ ASSERT_EQ(policy::kUpdateNeeded, manager_->StringifiedUpdateStatus());
+ manager_->ProcessEvent(policy::UpdateEvent::kOnNewAppRegistered);
+ EXPECT_EQ(policy::kUpdateNeeded, manager_->StringifiedUpdateStatus());
+}
} // namespace policy_test
} // namespace components
} // namespace test
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
index fc6ec369dc..192de6cd34 100644
--- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
@@ -876,6 +876,8 @@ class PolicyManagerImpl : public PolicyManager {
int32_t timespan_seconds) OVERRIDE;
// Interface StatisticsManager (end)
+ void ResetTimeout() OVERRIDE;
+
protected:
#ifdef USE_HMI_PTU_DECRYPTION
/**
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 9c73d88e63..743b9eff6c 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -40,7 +40,7 @@
#include <sstream>
#include "interfaces/MOBILE_API.h"
-#include "json/features.h"
+#include "json/json_features.h"
#include "json/reader.h"
#include "json/writer.h"
#include "smart_objects/enum_schema_item.h"
@@ -1853,13 +1853,16 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
return false;
}
+ Json::CharReaderBuilder reader_builder;
+ Json::CharReaderBuilder::strictMode(&reader_builder.settings_);
+ auto reader =
+ std::unique_ptr<Json::CharReader>(reader_builder.newCharReader());
Json::Value value;
- Json::Reader reader(Json::Features::strictMode());
+ JSONCPP_STRING err;
std::string json(json_string.begin(), json_string.end());
- if (!reader.parse(json.c_str(), value)) {
- LOG4CXX_FATAL(
- logger_,
- "Preloaded PT is corrupted: " << reader.getFormattedErrorMessages());
+ const size_t json_len = json.length();
+ if (!reader->parse(json.c_str(), json.c_str() + json_len, &value, &err)) {
+ LOG4CXX_FATAL(logger_, "Preloaded PT is corrupted: " << err);
return false;
}
@@ -1868,9 +1871,10 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
table = policy_table::Table(&value);
- Json::StyledWriter s_writer;
+ Json::StreamWriterBuilder writer_builder;
LOG4CXX_DEBUG(logger_, "PT out:");
- LOG4CXX_DEBUG(logger_, s_writer.write(table.ToJsonValue()));
+ LOG4CXX_DEBUG(logger_,
+ Json::writeString(writer_builder, table.ToJsonValue()));
MakeLowerCaseAppNames(table);
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index 2fef8de1d8..22205763a9 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -36,13 +36,13 @@
#include <limits>
#include <queue>
#include <set>
-#include "json/reader.h"
#include "json/writer.h"
#include "policy/policy_helper.h"
#include "policy/policy_table.h"
#include "policy/pt_representation.h"
#include "utils/date_time.h"
#include "utils/file_system.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include "utils/logger.h"
#include "config_profile/profile.h"
@@ -89,9 +89,10 @@ void PolicyManagerImpl::set_listener(PolicyListener* listener) {
std::shared_ptr<policy_table::Table> PolicyManagerImpl::Parse(
const BinaryMessage& pt_content) {
std::string json(pt_content.begin(), pt_content.end());
+ utils::JsonReader reader;
Json::Value value;
- Json::Reader reader;
- if (reader.parse(json.c_str(), value)) {
+
+ if (reader.parse(json, &value)) {
return std::make_shared<policy_table::Table>(&value);
} else {
return std::make_shared<policy_table::Table>();
@@ -103,9 +104,10 @@ std::shared_ptr<policy_table::Table> PolicyManagerImpl::Parse(
std::shared_ptr<policy_table::Table> PolicyManagerImpl::ParseArray(
const BinaryMessage& pt_content) {
std::string json(pt_content.begin(), pt_content.end());
+ utils::JsonReader reader;
Json::Value value;
- Json::Reader reader;
- if (reader.parse(json.c_str(), value)) {
+
+ if (reader.parse(json, &value)) {
// For PT Update received from SDL Server.
if (value["data"].size() != 0) {
Json::Value data = value["data"];
@@ -599,8 +601,8 @@ bool PolicyManagerImpl::RequestPTUpdate(const PTUIterationType iteration_type) {
IsPTValid(policy_table_snapshot, policy_table::PT_SNAPSHOT);
Json::Value value = policy_table_snapshot->ToJsonValue();
- Json::FastWriter writer;
- std::string message_string = writer.write(value);
+ Json::StreamWriterBuilder writer_builder;
+ std::string message_string = Json::writeString(writer_builder, value);
LOG4CXX_DEBUG(logger_, "Snapshot contents is : " << message_string);
@@ -1605,6 +1607,16 @@ void PolicyManagerImpl::set_cache_manager(
cache_ = std::shared_ptr<CacheManagerInterface>(cache_manager);
}
+void PolicyManagerImpl::ResetTimeout() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (update_status_manager_.IsUpdatePending()) {
+ if (timer_retry_sequence_.is_running()) {
+ timer_retry_sequence_.Stop();
+ }
+ timer_retry_sequence_.Start(cache_->TimeoutResponse(), timer::kSingleShot);
+ }
+}
+
void PolicyManagerImpl::OnPTUIterationTimeout() {
LOG4CXX_DEBUG(logger_, "Start new retry sequence");
diff --git a/src/components/policy/policy_regular/test/generated_code_test.cc b/src/components/policy/policy_regular/test/generated_code_test.cc
index 671103bf51..2b79ef67fe 100644
--- a/src/components/policy/policy_regular/test/generated_code_test.cc
+++ b/src/components/policy/policy_regular/test/generated_code_test.cc
@@ -49,8 +49,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTPreloadJsonIsValid) {
std::ifstream json_file("sdl_preloaded_pt.json");
ASSERT_TRUE(json_file.is_open());
Json::Value valid_table;
- Json::Reader reader;
- ASSERT_TRUE(reader.parse(json_file, valid_table));
+ Json::CharReaderBuilder reader_builder;
+ ASSERT_TRUE(
+ Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr));
Table table(&valid_table);
table.SetPolicyTableType(rpc::policy_table_interface_base::PT_PRELOADED);
ASSERT_RPCTYPE_VALID(table);
@@ -60,8 +61,9 @@ TEST(PolicyGeneratedCodeTest, TestValidPTUpdateJsonIsValid) {
std::ifstream json_file("valid_sdl_pt_update.json");
ASSERT_TRUE(json_file.is_open());
Json::Value valid_table;
- Json::Reader reader;
- ASSERT_TRUE(reader.parse(json_file, valid_table));
+ Json::CharReaderBuilder reader_builder;
+ ASSERT_TRUE(
+ Json::parseFromStream(reader_builder, json_file, &valid_table, nullptr));
Table table(&valid_table);
table.SetPolicyTableType(rpc::policy_table_interface_base::PT_UPDATE);
ASSERT_RPCTYPE_VALID(table);
diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
index e1f916e72f..abb5901690 100644
--- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
+++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
@@ -36,8 +36,8 @@
#include <vector>
#include "gtest/gtest.h"
-#include "json/reader.h"
#include "json/writer.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include "config_profile/profile.h"
#include "connection_handler/connection_handler.h"
@@ -305,10 +305,11 @@ class PolicyManagerImplTest2 : public ::testing::Test {
const Json::Value GetPTU(std::string file_name) {
// Get PTU
std::ifstream ifile(file_name);
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
json = root.toStyledString();
}
ifile.close();
@@ -331,9 +332,10 @@ class PolicyManagerImplTest2 : public ::testing::Test {
Json::Value AddWidgetSupportToPt(const std::string& section_name,
const uint32_t group_number) {
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
auto& groups =
root["policy_table"]["app_policies"][section_name]["groups"];
if (groups.empty()) {
@@ -585,8 +587,9 @@ Json::Value CreatePTforLoad() {
"}"
"}");
Json::Value table(Json::objectValue);
- Json::Reader reader;
- EXPECT_TRUE(reader.parse(load_table, table));
+ utils::JsonReader reader;
+
+ EXPECT_TRUE(reader.parse(load_table, &table));
return table;
}
@@ -646,10 +649,11 @@ TEST_F(PolicyManagerImplTest2, IsAppRevoked_SetRevokedAppID_ExpectAppRevoked) {
CreateLocalPT("sdl_preloaded_pt.json");
// Arrange
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
root["policy_table"]["app_policies"][app_id1] = Json::nullValue;
json = root.toStyledString();
}
@@ -703,10 +707,11 @@ TEST_F(PolicyManagerImplTest2,
ASSERT_TRUE(output.list_of_allowed_params.empty());
// Act
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
root["policy_table"]["app_policies"][app_id1] = Json::nullValue;
json = root.toStyledString();
}
@@ -870,10 +875,11 @@ TEST_F(PolicyManagerImplTest2,
manager->AddApplication(dev_id1, "1234", HmiTypes(policy_table::AHT_MEDIA));
// Emulate PTU with new policies for app added above
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
std::string json;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
// Add AppID with policies
root["policy_table"]["app_policies"]["1234"] =
Json::Value(Json::objectValue);
@@ -1416,9 +1422,10 @@ TEST_F(PolicyManagerImplTest2, ResetRetrySequence) {
TEST_F(PolicyManagerImplTest2, NextRetryTimeout_ExpectTimeoutsFromPT) {
// Arrange
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
Json::Value seconds_between_retries = Json::Value(Json::arrayValue);
seconds_between_retries =
root["policy_table"]["module_config"]["seconds_between_retries"];
@@ -1464,10 +1471,11 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) {
CreateLocalPT("sdl_preloaded_pt.json");
// Update preloadedPT
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
root["policy_table"]["module_config"]["preloaded_date"] =
new_data.new_date_;
Json::Value val(Json::objectValue);
@@ -1481,9 +1489,8 @@ TEST_F(PolicyManagerImplTest2, UpdatedPreloadedPT_ExpectLPT_IsUpdated) {
}
ifile.close();
- Json::StyledStreamWriter writer;
std::ofstream ofile("sdl_preloaded_pt.json");
- writer.write(ofile, root);
+ ofile << root;
ofile.flush();
ofile.close();
@@ -1533,9 +1540,10 @@ TEST_F(PolicyManagerImplTest2,
RetrySequenceDelaysSeconds_Expect_CorrectValues) {
// Arrange
std::ifstream ifile("sdl_preloaded_pt.json");
- Json::Reader reader;
+ Json::CharReaderBuilder reader_builder;
Json::Value root(Json::objectValue);
- if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ if (ifile.is_open() &&
+ Json::parseFromStream(reader_builder, ifile, &root, nullptr)) {
Json::Value seconds_between_retries = Json::Value(Json::arrayValue);
seconds_between_retries =
root["policy_table"]["module_config"]["seconds_between_retries"];
diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
index 8bb0fb22c6..30536bbaa4 100644
--- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
+++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc
@@ -1705,10 +1705,10 @@ TEST_F(SQLPTRepresentationTest,
table["policy_table"]["device_data"] = Json::Value(Json::objectValue);
table["policy_table"]["module_meta"] = Json::Value(Json::objectValue);
policy_table::Table expected(&table);
- Json::StyledWriter writer;
+ Json::StreamWriterBuilder writer_builder;
// Checks
- EXPECT_EQ(writer.write(expected.ToJsonValue()),
- writer.write(snapshot->ToJsonValue()));
+ EXPECT_EQ(Json::writeString(writer_builder, expected.ToJsonValue()),
+ Json::writeString(writer_builder, snapshot->ToJsonValue()));
EXPECT_EQ(expected.ToJsonValue().toStyledString(),
snapshot->ToJsonValue().toStyledString());
}
diff --git a/src/components/policy/policy_regular/test/vehicle_data_item_type_test.cc b/src/components/policy/policy_regular/test/vehicle_data_item_type_test.cc
index a2f7757936..02818887a5 100644
--- a/src/components/policy/policy_regular/test/vehicle_data_item_type_test.cc
+++ b/src/components/policy/policy_regular/test/vehicle_data_item_type_test.cc
@@ -30,8 +30,8 @@
* POSSIBILITY OF SUCH DAMAGE. */
#include "gtest/gtest.h"
-#include "json/reader.h"
#include "policy/policy_table/types.h"
+#include "utils/jsoncpp_reader_wrapper.h"
#include <type_traits>
@@ -139,11 +139,12 @@ class VehicleDataItemTypeTest : public ::testing::Test {
}
Json::Value json_;
- Json::Reader reader_;
+ utils::JsonReader reader_;
};
TEST_F(VehicleDataItemTypeTest, Initialize_Success) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
VehicleDataItem vdi(&json_);
EXPECT_TRUE(vdi.is_initialized());
@@ -156,7 +157,8 @@ TEST_F(VehicleDataItemTypeTest, Initialize_Failed) {
}
TEST_F(VehicleDataItemTypeTest, CheckConvertFromJsonToVehicleDataItem_Success) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
VehicleDataItem vdi(&json_);
EXPECT_TRUE((std::string)vdi.name == "VehicleDataItem");
@@ -178,7 +180,8 @@ TEST_F(VehicleDataItemTypeTest, CheckConvertFromJsonToVehicleDataItem_Success) {
}
TEST_F(VehicleDataItemTypeTest, CheckConvertFromVehicleDataItemToJson_Success) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
VehicleDataItem vdi(&json_);
auto jsonFrom = vdi.ToJsonValue();
@@ -193,7 +196,8 @@ TEST_F(VehicleDataItemTypeTest, CheckIsValid_Failed) {
}
TEST_F(VehicleDataItemTypeTest, CheckIsValid_Struct_Success) {
- reader_.parse(GetFullJsonString(GetFullJsonString()), json_);
+ std::string str = GetFullJsonString(GetFullJsonString());
+ reader_.parse(str, &json_);
VehicleDataItem vdi(&json_);
vdi.type = "Struct";
@@ -201,7 +205,9 @@ TEST_F(VehicleDataItemTypeTest, CheckIsValid_Struct_Success) {
}
TEST_F(VehicleDataItemTypeTest, CheckIsValid_Struct_EmptyParams_Failed) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
+
VehicleDataItem vdi(&json_);
vdi.type = "Struct";
@@ -209,7 +215,9 @@ TEST_F(VehicleDataItemTypeTest, CheckIsValid_Struct_EmptyParams_Failed) {
}
TEST_F(VehicleDataItemTypeTest, CheckIsValid_PODTypes_Success) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
+
VehicleDataItem vdi(&json_);
vdi.type = "Integer";
@@ -231,14 +239,16 @@ TEST_F(VehicleDataItemTypeTest, CheckEmptiness_True) {
}
TEST_F(VehicleDataItemTypeTest, CheckEmptiness_False) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
VehicleDataItem vdi(&json_);
EXPECT_TRUE(vdi.struct_not_empty());
}
TEST_F(VehicleDataItemTypeTest, CheckCopyConstructor) {
- reader_.parse(GetFullJsonString(), json_);
+ const std::string str = GetFullJsonString();
+ reader_.parse(str, &json_);
VehicleDataItem vdi1(&json_);
VehicleDataItem vdi2(vdi1);