summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorigapchuck <igapchuck@luxoft.com>2019-07-18 11:52:04 +0300
committerMykola Korniichuk <mkorniichuk@luxoft.com>2019-08-01 12:54:45 +0300
commit1bf2ae602afa55552761215d3e19c2916cbcf9d6 (patch)
tree25952738090d3666b688d06f153e21415a9725fa
parent81965e8fac1a4579fd37dbaf5f0c2fc812353b80 (diff)
downloadsdl_core-1bf2ae602afa55552761215d3e19c2916cbcf9d6.tar.gz
Add CustomVehicleData functionality for POLICY_EXTERNAL flow
Change max value url for external policy fixes for external flow * since unti validation for the database * empty vehicle data validation
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt6
-rw-r--r--src/components/include/policy/policy_external/policy/policy_manager.h7
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_cache_manager.h2
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_manager.h2
-rw-r--r--src/components/policy/policy_external/CMakeLists.txt86
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager.h7
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager_interface.h7
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h7
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/enums.h85
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/policy_enum_schema_factory.h66
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/types.h112
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_queries.h13
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_representation.h31
-rw-r--r--src/components/policy/policy_external/src/cache_manager.cc13
-rw-r--r--src/components/policy/policy_external/src/policy_helper.cc71
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc93
-rw-r--r--src/components/policy/policy_external/src/policy_table/enums.cc926
-rw-r--r--src/components/policy/policy_external/src/policy_table/types.cc458
-rw-r--r--src/components/policy/policy_external/src/policy_table/validation.cc43
-rw-r--r--src/components/policy/policy_external/src/sql_pt_queries.cc19
-rw-r--r--src/components/policy/policy_external/src/sql_pt_representation.cc445
-rw-r--r--src/components/policy/policy_external/test/include/policy/policy_manager_impl_test_base.h2
-rw-r--r--src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc7
-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.cc4
-rw-r--r--src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc18
-rw-r--r--src/components/policy/policy_external/test/sql_pt_representation_test.cc53
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc8
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc17
-rw-r--r--src/components/policy/policy_regular/test/policy_manager_impl_test.cc40
30 files changed, 1473 insertions, 1180 deletions
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt
index 75eadbbe05..8b6b28a340 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt
@@ -44,9 +44,9 @@ file(GLOB SOURCES
${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc
${COMPONENTS_DIR}/application_manager/test/mock_application_helper.cc
${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc
- ${COMPONENTS_DIR}/policy/policy_regular/src/policy_table/types.cc
- ${COMPONENTS_DIR}/policy/policy_regular/src/policy_table/validation.cc
- ${COMPONENTS_DIR}/policy/policy_regular/src/policy_table/enums.cc
+ ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/types.cc
+ ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/validation.cc
+ ${COMPONENTS_DIR}/${POLICY_PATH}/src/policy_table/enums.cc
${COMMANDS_TEST_DIR}/hmi/*
${COMMANDS_TEST_DIR}/mobile/*
${CMAKE_CURRENT_SOURCE_DIR}/custom_vehicle_data_manager_test.cc
diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h
index e008d64729..a4a1904b69 100644
--- a/src/components/include/policy/policy_external/policy/policy_manager.h
+++ b/src/components/include/policy/policy_external/policy/policy_manager.h
@@ -545,6 +545,13 @@ class PolicyManager : public usage_statistics::StatisticsManager {
const std::string& policy_app_id) const = 0;
/**
+ * @brief Gets vehicle data items
+ * @return Structure with vehicle data items
+ */
+ virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
+ const = 0;
+
+ /**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
index 49b2f36a9f..00ef99c1a2 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
@@ -76,6 +76,8 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds));
MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id));
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
+ MOCK_CONST_METHOD0(GetVehicleDataItems,
+ const std::vector<policy_table::VehicleDataItem>());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
void(std::vector<std::string>& enabled_apps));
MOCK_CONST_METHOD7(GetCloudAppParameters,
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
index e8065cdfaf..1cb24ad1a0 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
@@ -189,6 +189,8 @@ class MockPolicyManager : public PolicyManager {
GetAppRequestTypes,
const std::vector<std::string>(const std::string policy_app_id));
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
+ MOCK_CONST_METHOD0(GetVehicleDataItems,
+ const std::vector<policy_table::VehicleDataItem>());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
void(std::vector<std::string>& enabled_apps));
MOCK_CONST_METHOD7(GetCloudAppParameters,
diff --git a/src/components/policy/policy_external/CMakeLists.txt b/src/components/policy/policy_external/CMakeLists.txt
index e3911ac02b..cffe66b47e 100644
--- a/src/components/policy/policy_external/CMakeLists.txt
+++ b/src/components/policy/policy_external/CMakeLists.txt
@@ -28,6 +28,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
+include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/generators.cmake)
+
# --- Policy
set(target Policy)
set(install_destination bin)
@@ -37,13 +39,16 @@ set(library_name ${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_S
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
include_directories (
- include
- ${COMPONENTS_DIR}/rpc_base/include
+ ${POLICY_PATH}/include/
+ ${COMPONENTS_DIR}/
${COMPONENTS_DIR}/utils/include/
${COMPONENTS_DIR}/config_profile/include
+ ${COMPONENTS_DIR}/smart_objects/include/
+ ${COMPONENTS_DIR}/rpc_base/include
+ ${CMAKE_BINARY_DIR}/src/components/
${POLICY_GLOBAL_INCLUDE_PATH}/
- ${LOG4CXX_INCLUDE_DIRECTORY}
${BOOST_INCLUDE_DIR}
+ ${LOG4CXX_INCLUDE_DIRECTORY}
${JSONCPP_INCLUDE_DIRECTORY}
)
@@ -58,32 +63,39 @@ set(SOURCES
${POLICY_PATH}/src/cache_manager.cc
${POLICY_PATH}/src/access_remote_impl.cc
${COMPONENTS_DIR}/rpc_base/src/rpc_base/rpc_base.cc
- ${CMAKE_CURRENT_BINARY_DIR}/
)
-set (GENERATED_MOBILE_POLICY_TYPES "generated_MOBILE_API_policy_types")
-set(GENERATED_MOBILE_POLICY_TYPES_HPP "${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_MOBILE_POLICY_TYPES}.h")
-set(GENERATED_MOBILE_POLICY_TYPES_CPP "${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_MOBILE_POLICY_TYPES}.cc")
-generate_policy_types("${COMPONENTS_DIR}/interfaces/MOBILE_API.xml"
- "rpc::policy_table_interface_base"
- "mobile-policy-types" ${GENERATED_MOBILE_POLICY_TYPES})
-add_custom_target(
- ${GENERATED_MOBILE_POLICY_TYPES}
- DEPENDS ${GENERATED_MOBILE_POLICY_TYPES_HPP}
- DEPENDS ${GENERATED_MOBILE_POLICY_TYPES_CPP}
- )
-
-set (GENERATED_HMI_POLICY_TYPES "generated_HMI_API_policy_types")
-set(GENERATED_HMI_POLICY_TYPES_HPP "${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_HMI_POLICY_TYPES}.h")
-set(GENERATED_HMI_POLICY_TYPES_CPP "${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_HMI_POLICY_TYPES}.cc")
-generate_policy_types("${COMPONENTS_DIR}/interfaces/HMI_API.xml"
+set(GENERATED_MOBILE_POLICY_TYPES_CPP
+ "${CMAKE_CURRENT_BINARY_DIR}/generated_MOBILE_API_policy_types.cc"
+ "${CMAKE_CURRENT_BINARY_DIR}/generated_MOBILE_API_enum_schema_factory.cc")
+
+set(GENERATED_MOBILE_POLICY_TYPES_HPP
+ "${CMAKE_CURRENT_BINARY_DIR}/generated_MOBILE_API_policy_types.h")
+
+set(GENERATED_MOBILE_POLICY_TYPES
+ ${GENERATED_MOBILE_POLICY_TYPES_HPP}
+ ${GENERATED_MOBILE_POLICY_TYPES_CPP})
+
+generate_policy_types("${GENERATED_MOBILE_POLICY_TYPES}"
+ "${COMPONENTS_DIR}/interfaces/MOBILE_API.xml"
"rpc::policy_table_interface_base"
- "hmi-policy-types" ${GENERATED_HMI_POLICY_TYPES})
-add_custom_target(
- ${GENERATED_HMI_POLICY_TYPES}
- DEPENDS ${GENERATED_HMI_POLICY_TYPES_HPP}
- DEPENDS ${GENERATED_HMI_POLICY_TYPES_CPP}
- )
+ "mobile-policy-types")
+
+set(GENERATED_HMI_POLICY_TYPES_CPP
+ "${CMAKE_CURRENT_BINARY_DIR}/generated_HMI_API_policy_types.cc")
+
+set(GENERATED_HMI_POLICY_TYPES_HPP
+ "${CMAKE_CURRENT_BINARY_DIR}/generated_HMI_API_policy_types.h")
+
+set(GENERATED_HMI_POLICY_TYPES
+ ${GENERATED_HMI_POLICY_TYPES_HPP}
+ ${GENERATED_HMI_POLICY_TYPES_CPP})
+
+
+generate_policy_types("${GENERATED_HMI_POLICY_TYPES}"
+ "${COMPONENTS_DIR}/interfaces/HMI_API.xml"
+ "rpc::policy_table_interface_base"
+ "hmi-policy-types")
if (REMOTE_CONTROL)
list(APPEND SOURCES ${POLICY_PATH}/src/access_remote_impl.cc)
@@ -94,7 +106,13 @@ list(APPEND SOURCES
${POLICY_PATH}/src/sql_pt_ext_representation.cc
)
-set(LIBRARIES ConfigProfile policy_struct dbms jsoncpp Utils)
+set(LIBRARIES
+ ConfigProfile
+ policy_struct
+ dbms jsoncpp
+ Utils
+)
+
if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
# --- QDB Wrapper
include_directories (${COMPONENTS_DIR}/utils/include/utils)
@@ -129,16 +147,22 @@ install(TARGETS ${target}
set(struct_target policy_struct)
set(TABLE_STRUCT_SOURCES
+ ${GENERATED_MOBILE_POLICY_TYPES_CPP}
+ ${GENERATED_HMI_POLICY_TYPES_CPP}
${POLICY_PATH}/src/policy_table/enums.cc
${POLICY_PATH}/src/policy_table/types.cc
${POLICY_PATH}/src/policy_table/validation.cc
- ${GENERATED_HMI_POLICY_TYPES_CPP}
- ${GENERATED_MOBILE_POLICY_TYPES_CPP}
)
add_library(${struct_target} ${TABLE_STRUCT_SOURCES})
-target_link_libraries(${struct_target} Utils)
-add_dependencies(${struct_target} ${GENERATED_MOBILE_POLICY_TYPES})
+target_link_libraries(${struct_target}
+MOBILE_API
+HMI_API
+Utils
+SmartObjects
+formatters
+jsoncpp
+)
# --- Usage statistics
set(USAGE_STATISTICS_SOURCES
diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h
index bcabbbe189..44d265dc54 100644
--- a/src/components/policy/policy_external/include/policy/cache_manager.h
+++ b/src/components/policy/policy_external/include/policy/cache_manager.h
@@ -160,6 +160,13 @@ class CacheManager : public CacheManagerInterface {
const std::string& language) const OVERRIDE;
/**
+ * @brief Gets vehicle data items
+ * @return Structure with vehicle data items
+ */
+ virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
+ const OVERRIDE;
+
+ /**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
index 808be6e323..72d14b8add 100644
--- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h
+++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
@@ -168,6 +168,13 @@ class CacheManagerInterface {
virtual Json::Value GetPolicyTableData() const = 0;
/**
+ * @brief Gets vehicle data items
+ * @return Structure with vehicle data items
+ */
+ virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
+ const = 0;
+
+ /**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
* cloud application
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 1ce36ed7bc..a80b6a5fe3 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
@@ -585,6 +585,13 @@ class PolicyManagerImpl : public PolicyManager {
Json::Value GetPolicyTableData() const OVERRIDE;
/**
+ * @brief Gets vehicle data items
+ * @return Structure with vehicle data items
+ */
+ const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
+ const OVERRIDE;
+
+ /**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
* cloud application
diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h
index 23c3c30f41..380f52cb67 100644
--- a/src/components/policy/policy_external/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h
@@ -41,30 +41,6 @@
namespace rpc {
namespace policy_table_interface_base {
-enum Priority {
- P_EMERGENCY,
- P_NAVIGATION,
- P_VOICECOM,
- P_COMMUNICATION,
- P_NORMAL,
- P_PROJECTION,
- P_NONE,
-};
-
-bool IsValidEnum(Priority val);
-const char* EnumToJsonString(Priority val);
-bool EnumFromJsonString(const std::string& literal, Priority* result);
-
-enum HmiLevel {
- HL_BACKGROUND,
- HL_FULL,
- HL_LIMITED,
- HL_NONE,
-};
-bool IsValidEnum(HmiLevel val);
-const char* EnumToJsonString(HmiLevel val);
-bool EnumFromJsonString(const std::string& literal, HmiLevel* result);
-
enum Parameter {
P_GPS,
P_SPEED,
@@ -117,54 +93,6 @@ bool IsValidEnum(Parameter val);
const char* EnumToJsonString(Parameter val);
bool EnumFromJsonString(const std::string& literal, Parameter* result);
-enum AppHMIType {
- AHT_DEFAULT,
- AHT_COMMUNICATION,
- AHT_MEDIA,
- AHT_MESSAGING,
- AHT_NAVIGATION,
- AHT_INFORMATION,
- AHT_SOCIAL,
- AHT_BACKGROUND_PROCESS,
- AHT_TESTING,
- AHT_SYSTEM,
- AHT_PROJECTION,
- AHT_REMOTE_CONTROL,
-};
-bool IsValidEnum(AppHMIType val);
-const char* EnumToJsonString(AppHMIType val);
-bool EnumFromJsonString(const std::string& literal, AppHMIType* result);
-
-enum RequestType {
- RT_HTTP,
- RT_FILE_RESUME,
- RT_AUTH_REQUEST,
- RT_AUTH_CHALLENGE,
- RT_AUTH_ACK,
- RT_PROPRIETARY,
- RT_QUERY_APPS,
- RT_LAUNCH_APP,
- RT_LOCK_SCREEN_ICON_URL,
- RT_TRAFFIC_MESSAGE_CHANNEL,
- RT_DRIVER_PROFILE,
- RT_VOICE_SEARCH,
- RT_NAVIGATION,
- RT_PHONE,
- RT_CLIMATE,
- RT_SETTINGS,
- RT_VEHICLE_DIAGNOSTICS,
- RT_EMERGENCY,
- RT_MEDIA,
- RT_FOTA,
- RT_OEM_SPECIFIC,
- RT_ICON_URL,
- RT_EMPTY // Added to allow empty Request Types handling
-};
-
-bool IsValidEnum(RequestType val);
-const char* EnumToJsonString(RequestType val);
-bool EnumFromJsonString(const std::string& literal, RequestType* result);
-
enum Input {
I_GUI,
I_VUI,
@@ -173,19 +101,6 @@ bool IsValidEnum(Input val);
const char* EnumToJsonString(Input val);
bool EnumFromJsonString(const std::string& literal, Input* result);
-enum ModuleType {
- MT_CLIMATE,
- MT_RADIO,
- MT_SEAT,
- MT_AUDIO,
- MT_LIGHT,
- MT_HMI_SETTINGS,
- MT_EMPTY
-};
-bool IsValidEnum(ModuleType val);
-const char* EnumToJsonString(ModuleType val);
-bool EnumFromJsonString(const std::string& literal, ModuleType* result);
-
extern const std::string kDefaultApp;
extern const std::string kPreDataConsentApp;
extern const std::string kDeviceApp;
diff --git a/src/components/policy/policy_external/include/policy/policy_table/policy_enum_schema_factory.h b/src/components/policy/policy_external/include/policy/policy_table/policy_enum_schema_factory.h
new file mode 100644
index 0000000000..55664fb33c
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table/policy_enum_schema_factory.h
@@ -0,0 +1,66 @@
+/**
+ * @file generated_MOBILE_API_policy_enum_schema_factory.h
+ * @brief Generated class generated_MOBILE_API_policy_enum_schema_factory header
+ * file.
+ *
+ * Copyright (c) 2017, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H
+
+#include <memory>
+#include <string>
+
+#include "smart_objects/smart_schema.h"
+
+namespace rpc {
+namespace policy_table_interface_base {
+
+class EnumSchemaItemFactory {
+ public:
+ /**
+ * @brief Get enum schama from enum name
+ * Implementation of this function should be generated from MOBILE_API.xml
+ * @param enum_name enum name to get shema factory for
+ * @return shared pointer to shema factory or empty shared pointer if
+ * enum_name is wrong
+ */
+ static std::shared_ptr<ns_smart_device_link::ns_smart_objects::ISchemaItem>
+ Get(const std::string& enum_name);
+
+ static bool IsRPCSpecVehicleDataType(const std::string& vd_name);
+};
+
+} // namespace policy_table_interface_base
+} // namespace rpc
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H
diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h
index 8795e2690f..27af9626b7 100644
--- a/src/components/policy/policy_external/include/policy/policy_table/types.h
+++ b/src/components/policy/policy_external/include/policy/policy_table/types.h
@@ -37,7 +37,9 @@
#include "utils/macro.h"
#include "policy/policy_table/enums.h"
+#include "policy/policy_table/policy_enum_schema_factory.h"
#include "rpc_base/rpc_message.h"
+#include "utils/helpers.h"
namespace Json {
class Value;
@@ -48,6 +50,7 @@ struct AppLevel;
struct ApplicationParams;
struct ConsentRecords;
struct DeviceParams;
+struct EndpointProperty;
struct MessageLanguages;
struct MessageString;
struct RpcParameters;
@@ -69,16 +72,18 @@ typedef Array<Enum<AppHMIType>, 0, 255> AppHMITypes;
typedef Array<Enum<HmiLevel>, 0, 4> HmiLevels;
-typedef Array<Enum<Parameter>, 0, 100> Parameters;
+typedef Array<String<0, 255>, 0, 100> Parameters;
typedef Map<RpcParameters, 0, UINT_MAX> Rpc;
-typedef Array<String<10, 255>, 1, 3> URL;
+typedef Array<String<10, INT_MAX>, 1, 3> URL;
typedef Map<URL, 1, 255> URLList;
typedef Map<URLList, 1, 255> ServiceEndpoints;
+typedef Map<EndpointProperty, 0, 255> ServiceEndpointProperties;
+
typedef uint8_t NumberOfNotificationsType;
typedef Map<Integer<NumberOfNotificationsType, 0, 255>, 0, 7>
NumberOfNotificationsPerMinute;
@@ -348,6 +353,24 @@ struct Rpcs : CompositeType {
bool Validate() const;
};
+struct EndpointProperty : CompositeType {
+ public:
+ Optional<String<0, 100> > version;
+
+ EndpointProperty();
+ ~EndpointProperty();
+ explicit EndpointProperty(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ void SetPolicyTableType(PolicyTableType pt_type) OVERRIDE;
+
+ private:
+ bool Validate() const;
+};
+
struct ModuleConfig : CompositeType {
public:
Integer<uint8_t, 0, 255> exchange_after_x_ignition_cycles;
@@ -356,6 +379,7 @@ struct ModuleConfig : CompositeType {
Integer<uint16_t, 0, 65535> timeout_after_x_seconds;
SecondsBetweenRetries seconds_between_retries;
ServiceEndpoints endpoints;
+ Optional<ServiceEndpointProperties> endpoint_properties;
NumberOfNotificationsPerMinute notifications_per_minute_by_priority;
Optional<String<0, 100> > vehicle_make;
Optional<String<0, 100> > vehicle_model;
@@ -366,6 +390,8 @@ struct ModuleConfig : CompositeType {
Optional<Boolean> full_app_id_supported;
Optional<Boolean> lock_screen_dismissal_enabled;
+ static const std::string kDefaultOemMappingServiceName;
+
public:
ModuleConfig();
ModuleConfig(uint8_t exchange_after_x_ignition_cycles,
@@ -374,6 +400,7 @@ struct ModuleConfig : CompositeType {
uint16_t timeout_after_x_seconds,
const SecondsBetweenRetries& seconds_between_retries,
const ServiceEndpoints& endpoints,
+ const ServiceEndpointProperties& endpoint_properties,
const NumberOfNotificationsPerMinute&
notifications_per_minute_by_priority);
~ModuleConfig();
@@ -600,6 +627,86 @@ struct DeviceParams : CompositeType {
bool Validate() const;
};
+struct VehicleDataItem : CompositeType {
+ public:
+ static const std::vector<std::string> kPODTypes;
+
+ static const std::string kInteger;
+ static const std::string kStruct;
+ static const std::string kString;
+ static const std::string kFloat;
+ static const std::string kBoolean;
+ static const std::string kName;
+ static const std::string kParams;
+
+ String<0, 255> name;
+ String<0, 255> type;
+ String<0, 255> key;
+ Boolean mandatory;
+ Optional<Array<VehicleDataItem, 0, 255> > params;
+
+ Optional<Boolean> array;
+ Optional<String<0, 255> > since;
+ Optional<String<0, 255> > until;
+ Optional<Boolean> removed;
+ Optional<Boolean> deprecated;
+ Optional<Float<-INT32_MAX, INT32_MAX> > minvalue;
+ Optional<Float<-INT32_MAX, INT32_MAX> > maxvalue;
+ Optional<Integer<uint32_t, 0, UINT32_MAX> > minsize;
+ Optional<Integer<uint32_t, 0, UINT32_MAX> > maxsize;
+ Optional<Integer<uint32_t, 0, UINT32_MAX> > minlength;
+ Optional<Integer<uint32_t, 0, UINT_MAX> > maxlength;
+
+ VehicleDataItem();
+ VehicleDataItem(const VehicleDataItem& policy_table);
+ explicit VehicleDataItem(const Json::Value* value__);
+
+ bool operator==(const VehicleDataItem& vd);
+
+ ~VehicleDataItem();
+
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_not_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ /**
+ * @brief Validates type of vehicle data item according to
+ * POD types and generated from API enums.
+ * @return true if type is valid.
+ */
+ bool ValidateTypes() const;
+ bool IsPrimitiveType() const;
+
+ private:
+ bool Validate() const;
+};
+
+typedef Array<VehicleDataItem, 0, 255> VehicleDataItems;
+
+struct VehicleData : CompositeType {
+ public:
+ Optional<String<0, 100> > schema_version;
+ Optional<VehicleDataItems> schema_items;
+
+ VehicleData();
+ VehicleData(const VehicleData& vehicle_data);
+ VehicleData(const Json::Value* value__);
+ ~VehicleData();
+
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
struct PolicyTable : CompositeType {
public:
ApplicationPoliciesSection app_policies_section;
@@ -609,6 +716,7 @@ struct PolicyTable : CompositeType {
Optional<ModuleMeta> module_meta;
Optional<UsageAndErrorCounts> usage_and_error_counts;
Optional<DeviceData> device_data;
+ Optional<VehicleData> vehicle_data;
public:
PolicyTable();
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_queries.h
index f2aa2b907c..da3d035fd7 100644
--- a/src/components/policy/policy_external/include/policy/sql_pt_queries.h
+++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h
@@ -142,10 +142,21 @@ extern const std::string kDeleteModuleTypes;
extern const std::string kDeleteAllDevices;
extern const std::string kSelectDBVersion;
extern const std::string kUpdateDBVersion;
-extern const std::string kInsertVehicleDataItem;
extern const std::string kSelectVehicleDataItem;
+extern const std::string kInsertVehicleDataItem;
+extern const std::string kDeleteVehicleDataItems;
extern const std::string kInsertVehicleDataItemParams;
extern const std::string kSelectVehicleDataItemParams;
+extern const std::string kDeleteVehicleDataItemParams;
+extern const std::string kSelectVehicleDataItemWithVersion;
+extern const std::string kSelectNonParametrizedVehicleDataItems;
+extern const std::string kSelectParametrizedVehicleDataItemsKey;
+extern const std::string kSelectOEMMappingVersion;
+extern const std::string kSelectVehicleDataSchemaVersion;
+extern const std::string kInsertVehicleDataSchemaVersion;
+extern const std::string kSelectEndpointProperties;
+extern const std::string kInsertEndpointVersion;
+
} // namespace sql_pt
} // namespace policy
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_representation.h b/src/components/policy/policy_external/include/policy/sql_pt_representation.h
index 36572ecde4..36eae00e31 100644
--- a/src/components/policy/policy_external/include/policy/sql_pt_representation.h
+++ b/src/components/policy/policy_external/include/policy/sql_pt_representation.h
@@ -123,6 +123,9 @@ class SQLPTRepresentation : public virtual PTRepresentation {
policy_table::ConsumerFriendlyMessages* messages) const;
virtual bool GatherApplicationPoliciesSection(
policy_table::ApplicationPoliciesSection* policies) const;
+ virtual bool GatherVehicleDataItems(
+ policy_table::VehicleDataItems* vehicle_data_items) const;
+ virtual bool GatherVehicleData(policy_table::VehicleData* vehicle_data) const;
bool GatherAppGroup(const std::string& app_id,
policy_table::Strings* app_groups) const;
@@ -158,6 +161,9 @@ class SQLPTRepresentation : public virtual PTRepresentation {
virtual bool SaveSpecificAppPolicy(
const policy_table::ApplicationPolicies::value_type& app);
virtual bool SaveDevicePolicy(const policy_table::DevicePolicy& device);
+ virtual bool SaveVehicleDataItems(
+ const policy_table::VehicleDataItems& vehicle_data_items);
+ virtual bool SaveVehicleData(const policy_table::VehicleData& vehicle_data);
virtual bool SaveMessageString(const std::string& type,
const std::string& lang,
@@ -202,6 +208,26 @@ class SQLPTRepresentation : public virtual PTRepresentation {
virtual bool IsDBVersionActual() const OVERRIDE;
virtual bool UpdateDBVersion() const OVERRIDE;
+ policy_table::VehicleDataItems GetVehicleDataItem(
+ const std::string& name, const std::string& key) const;
+ bool InsertVehicleDataItem(
+ const policy_table::VehicleDataItem& vehicle_data_item);
+ bool VehicleDataItemExists(
+ const policy_table::VehicleDataItem& vehicle_data_item) const;
+
+ /**
+ * @brief Retrieves vehicle data items of type Struct (which contains params)
+ * from the database includeing these parameters.
+ * @return Array of parametrised VehicleDataItems (including params)
+ */
+ policy_table::VehicleDataItems SelectParameterizedVehicleDataItems() const;
+
+ /**
+ * @brief Retrieves vehicle data items of non Struct type from the database.
+ * @return Array of parameterised VehicleDataItems (including params)
+ */
+ policy_table::VehicleDataItems SelectNonParameterizedVehicleDataItems() const;
+
private:
utils::dbms::SQLDatabase* db_;
@@ -219,12 +245,17 @@ class SQLPTRepresentation : public virtual PTRepresentation {
const int32_t GetDBVersion() const;
bool SaveRpcs(int64_t group_id, const policy_table::Rpc& rpcs);
bool SaveServiceEndpoints(const policy_table::ServiceEndpoints& endpoints);
+ bool SaveServiceEndpointProperties(
+ const policy_table::ServiceEndpointProperties& endpoint_properties);
bool SaveSecondsBetweenRetries(
const policy_table::SecondsBetweenRetries& seconds);
bool SaveNumberOfNotificationsPerMinute(
const policy_table::NumberOfNotificationsPerMinute& notifications);
bool SaveMessageType(const std::string& type);
bool SaveLanguage(const std::string& code);
+ policy_table::VehicleDataItem PopulateVDIFromQuery(
+ const utils::dbms::SQLQuery& query) const;
+ bool DeleteVehicleDataItems() const;
bool is_in_memory;
bool SaveExternalConsentEntities(
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc
index f9645542c3..6ded517800 100644
--- a/src/components/policy/policy_external/src/cache_manager.cc
+++ b/src/components/policy/policy_external/src/cache_manager.cc
@@ -1426,6 +1426,19 @@ bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) {
return true;
}
+const std::vector<policy_table::VehicleDataItem>
+CacheManager::GetVehicleDataItems() const {
+ CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>());
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+
+ if (pt_->policy_table.vehicle_data.is_initialized() &&
+ pt_->policy_table.vehicle_data->schema_items.is_initialized()) {
+ return *(pt_->policy_table.vehicle_data->schema_items);
+ }
+
+ return std::vector<policy_table::VehicleDataItem>();
+}
+
Json::Value CacheManager::GetPolicyTableData() const {
return pt_->policy_table.ToJsonValue();
}
diff --git a/src/components/policy/policy_external/src/policy_helper.cc b/src/components/policy/policy_external/src/policy_helper.cc
index e8855bb11a..04efd711e4 100644
--- a/src/components/policy/policy_external/src/policy_helper.cc
+++ b/src/components/policy/policy_external/src/policy_helper.cc
@@ -46,7 +46,8 @@ namespace {
CREATE_LOGGERPTR_GLOBAL(logger_, "Policy")
-bool Compare(const StringsValueType& first, const StringsValueType& second) {
+bool IsDifferentStrings(const StringsValueType& first,
+ const StringsValueType& second) {
const std::string& first_str = first;
const std::string& second_str = second;
return (strcasecmp(first_str.c_str(), second_str.c_str()) < 0);
@@ -137,10 +138,10 @@ bool policy::CheckAppPolicy::HasRevokedGroups(
snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
policy_table::Strings groups_new = app_policy.second.groups;
- std::sort(groups_new.begin(), groups_new.end(), Compare);
+ std::sort(groups_new.begin(), groups_new.end(), IsDifferentStrings);
policy_table::Strings groups_curr = (*it).second.groups;
- std::sort(groups_curr.begin(), groups_curr.end(), Compare);
+ std::sort(groups_curr.begin(), groups_curr.end(), IsDifferentStrings);
StringsConstItr it_groups_new = groups_new.begin();
StringsConstItr it_groups_new_end = groups_new.end();
@@ -154,18 +155,7 @@ bool policy::CheckAppPolicy::HasRevokedGroups(
it_groups_new,
it_groups_new_end,
std::back_inserter(revoked_group_list),
- Compare);
-
- // Remove groups which are not required user consent
- policy_table::Strings::iterator it_revoked = revoked_group_list.begin();
- for (; revoked_group_list.end() != it_revoked;) {
- if (!IsConsentRequired(app_policy.first, std::string(*it_revoked))) {
- revoked_group_list.erase(it_revoked);
- it_revoked = revoked_group_list.begin();
- } else {
- ++it_revoked;
- }
- }
+ IsDifferentStrings);
if (revoked_groups) {
*revoked_groups = revoked_group_list;
@@ -181,10 +171,10 @@ bool policy::CheckAppPolicy::HasNewGroups(
snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
policy_table::Strings groups_new = app_policy.second.groups;
- std::sort(groups_new.begin(), groups_new.end(), Compare);
+ std::sort(groups_new.begin(), groups_new.end(), IsDifferentStrings);
policy_table::Strings groups_curr = (*it).second.groups;
- std::sort(groups_curr.begin(), groups_curr.end(), Compare);
+ std::sort(groups_curr.begin(), groups_curr.end(), IsDifferentStrings);
StringsConstItr it_groups_new = groups_new.begin();
StringsConstItr it_groups_new_end = groups_new.end();
@@ -192,13 +182,55 @@ bool policy::CheckAppPolicy::HasNewGroups(
StringsConstItr it_groups_curr = groups_curr.begin();
StringsConstItr it_groups_curr_end = groups_curr.end();
+ auto IsDifferentGroupContent =
+ [this](const StringsValueType& update_group_name,
+ const StringsValueType& snapshot_group_name) -> bool {
+ if (IsDifferentStrings(update_group_name, snapshot_group_name)) {
+ return true;
+ }
+
+ const auto& func_group_from_update =
+ update_->policy_table.functional_groupings.find(update_group_name);
+ const auto& func_group_from_snapshot =
+ snapshot_->policy_table.functional_groupings.find(snapshot_group_name);
+
+ const auto& update_fg_rpcs = func_group_from_update->second.rpcs;
+ const auto& snapshot_fg_rpcs = func_group_from_snapshot->second.rpcs;
+
+ if (update_fg_rpcs.is_null() || snapshot_fg_rpcs.is_null()) {
+ return !(update_fg_rpcs.is_null() && snapshot_fg_rpcs.is_null());
+ }
+
+ if (update_fg_rpcs.size() != snapshot_fg_rpcs.size()) {
+ return true;
+ }
+
+ for (const auto& rpc : update_fg_rpcs) {
+ const auto& old_rpc = snapshot_fg_rpcs.find(rpc.first);
+ if (snapshot_fg_rpcs.end() == old_rpc) {
+ return true;
+ }
+
+ const bool hmi_levels_same =
+ old_rpc->second.hmi_levels == rpc.second.hmi_levels;
+ const bool parameters_same =
+ *(old_rpc->second.parameters) == *(rpc.second.parameters);
+
+ if (!hmi_levels_same || !parameters_same) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
policy_table::Strings new_group_list;
std::set_difference(it_groups_new,
it_groups_new_end,
it_groups_curr,
it_groups_curr_end,
std::back_inserter(new_group_list),
- Compare);
+ IsDifferentGroupContent);
if (new_groups) {
*new_groups = new_group_list;
@@ -668,8 +700,7 @@ void FillNotificationData::UpdateParameters(
}
for (; it_parameters != it_parameters_end; ++it_parameters) {
- out_parameter[current_key_].insert(
- policy_table::EnumToJsonString(*it_parameters));
+ out_parameter[current_key_].insert(*it_parameters);
}
// We should reset ALL DISALLOWED flags if at least one parameter is allowed
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 eddf9d7032..c7abcf32b6 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -297,7 +297,9 @@ void FilterInvalidFunctions(policy_table::Rpc& rpcs) {
* schema
* @param rpc_parameters parameters to filter
*/
-void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) {
+void FilterInvalidRPCParameters(
+ policy_table::RpcParameters& rpc_parameters,
+ const std::vector<policy_table::VehicleDataItem>& vehicle_data_items) {
policy_table::HmiLevels valid_hmi_levels;
for (const auto& hmi_level : rpc_parameters.hmi_levels) {
if (hmi_level.is_valid()) {
@@ -306,10 +308,31 @@ void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) {
}
rpc_parameters.hmi_levels.swap(valid_hmi_levels);
+ auto ParamExists =
+ [&vehicle_data_items](const rpc::String<0, 255>& param_name) {
+ policy_table::Parameter parameter_enum;
+ if (policy_table::EnumFromJsonString(param_name, &parameter_enum)) {
+ return true;
+ }
+
+ // In case when this collection is empty that means collection is not
+ // initialized
+ if (vehicle_data_items.empty()) {
+ return false;
+ }
+
+ for (const auto& vdi : vehicle_data_items) {
+ if (param_name == vdi.name) {
+ return true;
+ }
+ }
+ return false;
+ };
+
policy_table::Parameters valid_params;
const policy_table::Parameters& params = *(rpc_parameters.parameters);
for (const auto& param : params) {
- if (param.is_valid()) {
+ if (param.is_valid() && ParamExists(param)) {
valid_params.push_back(param);
}
}
@@ -399,7 +422,9 @@ void FilterInvalidApplicationParameters(
* @brief FilterPolicyTable filter values that not present in schema
* @param pt policy table to filter
*/
-void FilterPolicyTable(policy_table::PolicyTable& pt) {
+void FilterPolicyTable(
+ policy_table::PolicyTable& pt,
+ const std::vector<policy_table::VehicleDataItem>& current_vd_items) {
policy_table::ModuleConfig& module_config = pt.module_config;
if (module_config.is_initialized() &&
module_config.notifications_per_minute_by_priority.is_initialized()) {
@@ -418,8 +443,18 @@ void FilterPolicyTable(policy_table::PolicyTable& pt) {
policy_table::Rpc& rpcs = group.second.rpcs;
FilterInvalidFunctions(rpcs);
+ policy_table::VehicleDataItems vehicle_data_items;
+
+ if (!pt.vehicle_data->struct_empty()) {
+ vehicle_data_items =
+ pt.vehicle_data.is_initialized() &&
+ pt.vehicle_data->schema_items.is_initialized()
+ ? *pt.vehicle_data->schema_items
+ : current_vd_items;
+ }
+
for (auto& func : rpcs) {
- FilterInvalidRPCParameters(func.second);
+ FilterInvalidRPCParameters(func.second, vehicle_data_items);
}
}
}
@@ -440,15 +475,6 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
}
file_system::DeleteFile(file);
- FilterPolicyTable(pt_update->policy_table);
- if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
- wrong_ptu_update_received_ = true;
- update_status_manager_.OnWrongUpdateReceived();
- return false;
- }
-
- update_status_manager_.OnValidUpdateReceived();
- cache_->SaveUpdateRequired(false);
{
sync_primitives::AutoLock lock(apps_registration_lock_);
@@ -464,13 +490,21 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
return false;
}
- // Checking of difference between PTU and current policy state
- // Must to be done before PTU applying since it is possible, that functional
- // groups, which had been present before are absent in PTU and will be
- // removed after update. So in case of revoked groups system has to know
- // names and ids of revoked groups before they will be removed.
- CheckAppPolicyResults results =
- CheckPermissionsChanges(pt_update, policy_table_snapshot);
+ auto current_vd_items = GetVehicleDataItems();
+
+ FilterPolicyTable(pt_update->policy_table, current_vd_items);
+ if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
+ wrong_ptu_update_received_ = true;
+ update_status_manager_.OnWrongUpdateReceived();
+ return false;
+ }
+
+ update_status_manager_.OnValidUpdateReceived();
+ cache_->SaveUpdateRequired(false);
+
+ // Replace predefined policies with its actual setting, e.g. "123":"default"
+ // to actual values of default section
+ UnwrapAppPolicies(pt_update->policy_table.app_policies_section.apps);
// Replace current data with updated
if (!cache_->ApplyUpdate(*pt_update)) {
@@ -481,6 +515,9 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
return false;
}
+ CheckAppPolicyResults results =
+ CheckPermissionsChanges(pt_update, policy_table_snapshot);
+
ExternalConsentStatus status = cache_->GetExternalConsentStatus();
GroupsByExternalConsentStatus groups_by_status =
cache_->GetGroupsWithSameEntities(status);
@@ -528,10 +565,6 @@ CheckAppPolicyResults PolicyManagerImpl::CheckPermissionsChanges(
const std::shared_ptr<policy_table::Table> snapshot) {
LOG4CXX_INFO(logger_, "Checking incoming permissions.");
- // Replace predefined policies with its actual setting, e.g. "123":"default"
- // to actual values of default section
- UnwrapAppPolicies(pt_update->policy_table.app_policies_section.apps);
-
CheckAppPolicyResults out_results;
std::for_each(pt_update->policy_table.app_policies_section.apps.begin(),
pt_update->policy_table.app_policies_section.apps.end(),
@@ -745,6 +778,11 @@ const std::vector<std::string> PolicyManagerImpl::GetAppRequestSubTypes(
return request_subtypes;
}
+const std::vector<policy_table::VehicleDataItem>
+PolicyManagerImpl::GetVehicleDataItems() const {
+ return cache_->GetVehicleDataItems();
+}
+
Json::Value PolicyManagerImpl::GetPolicyTableData() const {
return cache_->GetPolicyTableData();
}
@@ -979,7 +1017,12 @@ void PolicyManagerImpl::CheckPermissions(const PTString& app_id,
result.hmi_level_permitted = kRpcUserDisallowed;
} else if (!result.IsAnyAllowed(rpc_params)) {
LOG4CXX_DEBUG(logger_, "There are no parameters allowed.");
- result.hmi_level_permitted = kRpcDisallowed;
+
+ if (!result.list_of_undefined_params.empty()) {
+ result.hmi_level_permitted = kRpcAllowed;
+ } else {
+ result.hmi_level_permitted = kRpcDisallowed;
+ }
}
}
diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc
index 4c95f62eca..6109619757 100644
--- a/src/components/policy/policy_external/src/policy_table/enums.cc
+++ b/src/components/policy/policy_external/src/policy_table/enums.cc
@@ -3,118 +3,6 @@
namespace rpc {
namespace policy_table_interface_base {
-bool IsValidEnum(Priority val) {
- switch (val) {
- case P_EMERGENCY:
- return true;
- case P_NAVIGATION:
- return true;
- case P_VOICECOM:
- return true;
- case P_COMMUNICATION:
- return true;
- case P_NORMAL:
- return true;
- case P_PROJECTION:
- return true;
- case P_NONE:
- return true;
- default:
- return false;
- }
-}
-const char* EnumToJsonString(Priority val) {
- switch (val) {
- case P_EMERGENCY:
- return "EMERGENCY";
- case P_NAVIGATION:
- return "NAVIGATION";
- case P_VOICECOM:
- return "VOICECOM";
- case P_COMMUNICATION:
- return "COMMUNICATION";
- case P_NORMAL:
- return "NORMAL";
- case P_PROJECTION:
- return "PROJECTION";
- case P_NONE:
- return "NONE";
- default:
- return "";
- }
-}
-bool EnumFromJsonString(const std::string& literal, Priority* result) {
- if ("EMERGENCY" == literal) {
- *result = P_EMERGENCY;
- return true;
- } else if ("NAVIGATION" == literal) {
- *result = P_NAVIGATION;
- return true;
- } else if ("VOICECOM" == literal) {
- *result = P_VOICECOM;
- return true;
- } else if ("COMMUNICATION" == literal) {
- *result = P_COMMUNICATION;
- return true;
- } else if ("NORMAL" == literal) {
- *result = P_NORMAL;
- return true;
- } else if ("PROJECTION" == literal) {
- *result = P_PROJECTION;
- return true;
- } else if ("NONE" == literal) {
- *result = P_NONE;
- return true;
- } else {
- return false;
- }
-}
-
-bool IsValidEnum(HmiLevel val) {
- switch (val) {
- case HL_BACKGROUND:
- return true;
- case HL_FULL:
- return true;
- case HL_LIMITED:
- return true;
- case HL_NONE:
- return true;
- default:
- return false;
- }
-}
-const char* EnumToJsonString(HmiLevel val) {
- switch (val) {
- case HL_BACKGROUND:
- return "BACKGROUND";
- case HL_FULL:
- return "FULL";
- case HL_LIMITED:
- return "LIMITED";
- case HL_NONE:
- return "NONE";
- default:
- return "";
- }
-}
-bool EnumFromJsonString(const std::string& literal, HmiLevel* result) {
- if ("BACKGROUND" == literal) {
- *result = HL_BACKGROUND;
- return true;
- } else if ("FULL" == literal) {
- *result = HL_FULL;
- return true;
- } else if ("LIMITED" == literal) {
- *result = HL_LIMITED;
- return true;
- } else if ("NONE" == literal) {
- *result = HL_NONE;
- return true;
- } else {
- return false;
- }
-}
bool IsValidEnum(Parameter val) {
switch (val) {
@@ -451,108 +339,6 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
}
}
-bool IsValidEnum(AppHMIType val) {
- switch (val) {
- case AHT_DEFAULT:
- return true;
- case AHT_COMMUNICATION:
- return true;
- case AHT_MEDIA:
- return true;
- case AHT_MESSAGING:
- return true;
- case AHT_NAVIGATION:
- return true;
- case AHT_INFORMATION:
- return true;
- case AHT_SOCIAL:
- return true;
- case AHT_BACKGROUND_PROCESS:
- return true;
- case AHT_TESTING:
- return true;
- case AHT_SYSTEM:
- return true;
- case AHT_PROJECTION:
- return true;
- case AHT_REMOTE_CONTROL:
- return true;
- default:
- return false;
- }
-}
-const char* EnumToJsonString(AppHMIType val) {
- switch (val) {
- case AHT_DEFAULT:
- return "DEFAULT";
- case AHT_COMMUNICATION:
- return "COMMUNICATION";
- case AHT_MEDIA:
- return "MEDIA";
- case AHT_MESSAGING:
- return "MESSAGING";
- case AHT_NAVIGATION:
- return "NAVIGATION";
- case AHT_INFORMATION:
- return "INFORMATION";
- case AHT_SOCIAL:
- return "SOCIAL";
- case AHT_BACKGROUND_PROCESS:
- return "BACKGROUND_PROCESS";
- case AHT_TESTING:
- return "TESTING";
- case AHT_SYSTEM:
- return "SYSTEM";
- case AHT_PROJECTION:
- return "PROJECTION";
- case AHT_REMOTE_CONTROL:
- return "REMOTE_CONTROL";
- default:
- return "";
- }
-}
-bool EnumFromJsonString(const std::string& literal, AppHMIType* result) {
- if ("DEFAULT" == literal) {
- *result = AHT_DEFAULT;
- return true;
- } else if ("COMMUNICATION" == literal) {
- *result = AHT_COMMUNICATION;
- return true;
- } else if ("MEDIA" == literal) {
- *result = AHT_MEDIA;
- return true;
- } else if ("MESSAGING" == literal) {
- *result = AHT_MESSAGING;
- return true;
- } else if ("NAVIGATION" == literal) {
- *result = AHT_NAVIGATION;
- return true;
- } else if ("INFORMATION" == literal) {
- *result = AHT_INFORMATION;
- return true;
- } else if ("SOCIAL" == literal) {
- *result = AHT_SOCIAL;
- return true;
- } else if ("BACKGROUND_PROCESS" == literal) {
- *result = AHT_BACKGROUND_PROCESS;
- return true;
- } else if ("TESTING" == literal) {
- *result = AHT_TESTING;
- return true;
- } else if ("SYSTEM" == literal) {
- *result = AHT_SYSTEM;
- return true;
- } else if ("PROJECTION" == literal) {
- *result = AHT_PROJECTION;
- return true;
- } else if ("REMOTE_CONTROL" == literal) {
- *result = AHT_REMOTE_CONTROL;
- return true;
- } else {
- return false;
- }
-}
-
bool IsValidEnum(Input val) {
switch (val) {
case I_GUI:
@@ -563,6 +349,7 @@ bool IsValidEnum(Input val) {
return false;
}
}
+
const char* EnumToJsonString(Input val) {
switch (val) {
case I_GUI:
@@ -585,717 +372,6 @@ bool EnumFromJsonString(const std::string& literal, Input* result) {
}
}
-bool IsValidEnum(RequestType val) {
- switch (val) {
- case RT_HTTP:
- return true;
- case RT_FILE_RESUME:
- return true;
- case RT_AUTH_REQUEST:
- return true;
- case RT_AUTH_CHALLENGE:
- return true;
- case RT_AUTH_ACK:
- return true;
- case RT_PROPRIETARY:
- return true;
- case RT_QUERY_APPS:
- return true;
- case RT_LAUNCH_APP:
- return true;
- case RT_LOCK_SCREEN_ICON_URL:
- return true;
- case RT_TRAFFIC_MESSAGE_CHANNEL:
- return true;
- case RT_DRIVER_PROFILE:
- return true;
- case RT_VOICE_SEARCH:
- return true;
- case RT_NAVIGATION:
- return true;
- case RT_PHONE:
- return true;
- case RT_CLIMATE:
- return true;
- case RT_SETTINGS:
- return true;
- case RT_VEHICLE_DIAGNOSTICS:
- return true;
- case RT_EMERGENCY:
- return true;
- case RT_MEDIA:
- return true;
- case RT_FOTA:
- return true;
- case RT_OEM_SPECIFIC:
- return true;
- case RT_ICON_URL:
- return true;
- case RT_EMPTY:
- return true;
- default:
- return false;
- }
-}
-
-const char* EnumToJsonString(RequestType val) {
- switch (val) {
- case RT_HTTP:
- return "HTTP";
- case RT_FILE_RESUME:
- return "FILE_RESUME";
- case RT_AUTH_REQUEST:
- return "AUTH_REQUEST";
- case RT_AUTH_CHALLENGE:
- return "AUTH_CHALLENGE";
- case RT_AUTH_ACK:
- return "AUTH_ACK";
- case RT_PROPRIETARY:
- return "PROPRIETARY";
- case RT_QUERY_APPS:
- return "QUERY_APPS";
- case RT_LAUNCH_APP:
- return "LAUNCH_APP";
- case RT_LOCK_SCREEN_ICON_URL:
- return "LOCK_SCREEN_ICON_URL";
- case RT_TRAFFIC_MESSAGE_CHANNEL:
- return "TRAFFIC_MESSAGE_CHANNEL";
- case RT_DRIVER_PROFILE:
- return "DRIVER_PROFILE";
- case RT_VOICE_SEARCH:
- return "VOICE_SEARCH";
- case RT_NAVIGATION:
- return "NAVIGATION";
- case RT_PHONE:
- return "PHONE";
- case RT_CLIMATE:
- return "CLIMATE";
- case RT_SETTINGS:
- return "SETTINGS";
- case RT_VEHICLE_DIAGNOSTICS:
- return "VEHICLE_DIAGNOSTICS";
- case RT_EMERGENCY:
- return "EMERGENCY";
- case RT_MEDIA:
- return "MEDIA";
- case RT_FOTA:
- return "FOTA";
- case RT_OEM_SPECIFIC:
- return "OEM_SPECIFIC";
- case RT_ICON_URL:
- return "ICON_URL";
- case RT_EMPTY:
- return "EMPTY";
- default:
- return "";
- }
-}
-
-bool EnumFromJsonString(const std::string& literal, RequestType* result) {
- if ("HTTP" == literal) {
- *result = RT_HTTP;
- return true;
- }
- if ("FILE_RESUME" == literal) {
- *result = RT_FILE_RESUME;
- return true;
- }
- if ("AUTH_REQUEST" == literal) {
- *result = RT_AUTH_REQUEST;
- return true;
- }
- if ("AUTH_CHALLENGE" == literal) {
- *result = RT_AUTH_CHALLENGE;
- return true;
- }
- if ("AUTH_ACK" == literal) {
- *result = RT_AUTH_ACK;
- return true;
- }
- if ("PROPRIETARY" == literal) {
- *result = RT_PROPRIETARY;
- return true;
- }
- if ("QUERY_APPS" == literal) {
- *result = RT_QUERY_APPS;
- return true;
- }
- if ("LAUNCH_APP" == literal) {
- *result = RT_LAUNCH_APP;
- return true;
- }
- if ("LOCK_SCREEN_ICON_URL" == literal) {
- *result = RT_LOCK_SCREEN_ICON_URL;
- return true;
- }
- if ("TRAFFIC_MESSAGE_CHANNEL" == literal) {
- *result = RT_TRAFFIC_MESSAGE_CHANNEL;
- return true;
- }
- if ("DRIVER_PROFILE" == literal) {
- *result = RT_DRIVER_PROFILE;
- return true;
- }
- if ("VOICE_SEARCH" == literal) {
- *result = RT_VOICE_SEARCH;
- return true;
- }
- if ("NAVIGATION" == literal) {
- *result = RT_NAVIGATION;
- return true;
- }
- if ("PHONE" == literal) {
- *result = RT_PHONE;
- return true;
- }
- if ("CLIMATE" == literal) {
- *result = RT_CLIMATE;
- return true;
- }
- if ("SETTINGS" == literal) {
- *result = RT_SETTINGS;
- return true;
- }
- if ("VEHICLE_DIAGNOSTICS" == literal) {
- *result = RT_VEHICLE_DIAGNOSTICS;
- return true;
- }
- if ("EMERGENCY" == literal) {
- *result = RT_EMERGENCY;
- return true;
- }
- if ("MEDIA" == literal) {
- *result = RT_MEDIA;
- return true;
- }
- if ("FOTA" == literal) {
- *result = RT_FOTA;
- return true;
- }
- if ("OEM_SPECIFIC" == literal) {
- *result = RT_OEM_SPECIFIC;
- return true;
- }
- if ("ICON_URL" == literal) {
- *result = RT_ICON_URL;
- return true;
- }
- if ("EMPTY" == literal) {
- *result = RT_EMPTY;
- return true;
- } else {
- return false;
- }
-}
-
-bool IsValidEnum(ModuleType val) {
- switch (val) {
- case MT_CLIMATE:
- return true;
- case MT_RADIO:
- return true;
- case MT_AUDIO:
- return true;
- case MT_LIGHT:
- return true;
- case MT_HMI_SETTINGS:
- return true;
- case MT_SEAT:
- return true;
- case MT_EMPTY:
- return true;
- default:
- return false;
- }
-}
-const char* EnumToJsonString(ModuleType val) {
- switch (val) {
- case MT_CLIMATE:
- return "CLIMATE";
- case MT_RADIO:
- return "RADIO";
- case MT_AUDIO:
- return "AUDIO";
- case MT_LIGHT:
- return "LIGHT";
- case MT_HMI_SETTINGS:
- return "HMI_SETTINGS";
- case MT_SEAT:
- return "SEAT";
- case MT_EMPTY:
- return "EMPTY";
- default:
- return "";
- }
-}
-
-bool EnumFromJsonString(const std::string& literal, ModuleType* result) {
- if ("CLIMATE" == literal) {
- *result = MT_CLIMATE;
- return true;
- } else if ("RADIO" == literal) {
- *result = MT_RADIO;
- return true;
- } else if ("SEAT" == literal) {
- *result = MT_SEAT;
- return true;
- } else if ("AUDIO" == literal) {
- *result = MT_AUDIO;
- return true;
- } else if ("LIGHT" == literal) {
- *result = MT_LIGHT;
- return true;
- } else if ("HMI_SETTINGS" == literal) {
- *result = MT_HMI_SETTINGS;
- return true;
- } else if ("EMPTY" == literal) {
- *result = MT_EMPTY;
- return true;
- } else {
- return false;
- }
-}
-
-bool IsValidEnum(HybridAppPreference val) {
- return strlen(EnumToJsonString(val)) > 0;
-}
-
-const char* EnumToJsonString(HybridAppPreference val) {
- switch (val) {
- case HAP_MOBILE:
- return "MOBILE";
- case HAP_CLOUD:
- return "CLOUD";
- case HAP_BOTH:
- return "BOTH";
- default:
- return "";
- }
-}
-
-bool EnumFromJsonString(const std::string& literal,
- HybridAppPreference* result) {
- if ("MOBILE" == literal) {
- *result = HAP_MOBILE;
- return true;
- } else if ("CLOUD" == literal) {
- *result = HAP_CLOUD;
- return true;
- } else if ("BOTH" == literal) {
- *result = HAP_BOTH;
- return true;
- }
- return false;
-}
-
-bool EnumFromJsonString(const std::string& literal, FunctionID* result) {
- if ("RegisterAppInterface" == literal) {
- *result = RegisterAppInterfaceID;
- return true;
- }
-
- if ("UnregisterAppInterface" == literal) {
- *result = UnregisterAppInterfaceID;
- return true;
- }
-
- if ("SetGlobalProperties" == literal) {
- *result = SetGlobalPropertiesID;
- return true;
- }
-
- if ("ResetGlobalProperties" == literal) {
- *result = ResetGlobalPropertiesID;
- return true;
- }
-
- if ("AddCommand" == literal) {
- *result = AddCommandID;
- return true;
- }
-
- if ("DeleteCommand" == literal) {
- *result = DeleteCommandID;
- return true;
- }
-
- if ("AddSubMenu" == literal) {
- *result = AddSubMenuID;
- return true;
- }
-
- if ("DeleteSubMenu" == literal) {
- *result = DeleteSubMenuID;
- return true;
- }
-
- if ("CreateInteractionChoiceSet" == literal) {
- *result = CreateInteractionChoiceSetID;
- return true;
- }
-
- if ("PerformInteraction" == literal) {
- *result = PerformInteractionID;
- return true;
- }
-
- if ("DeleteInteractionChoiceSet" == literal) {
- *result = DeleteInteractionChoiceSetID;
- return true;
- }
-
- if ("Alert" == literal) {
- *result = AlertID;
- return true;
- }
-
- if ("Show" == literal) {
- *result = ShowID;
- return true;
- }
-
- if ("Speak" == literal) {
- *result = SpeakID;
- return true;
- }
-
- if ("SetMediaClockTimer" == literal) {
- *result = SetMediaClockTimerID;
- return true;
- }
-
- if ("PerformAudioPassThru" == literal) {
- *result = PerformAudioPassThruID;
- return true;
- }
-
- if ("EndAudioPassThru" == literal) {
- *result = EndAudioPassThruID;
- return true;
- }
-
- if ("SubscribeButton" == literal) {
- *result = SubscribeButtonID;
- return true;
- }
-
- if ("UnsubscribeButton" == literal) {
- *result = UnsubscribeButtonID;
- return true;
- }
-
- if ("SubscribeVehicleData" == literal) {
- *result = SubscribeVehicleDataID;
- return true;
- }
-
- if ("UnsubscribeVehicleData" == literal) {
- *result = UnsubscribeVehicleDataID;
- return true;
- }
-
- if ("GetVehicleData" == literal) {
- *result = GetVehicleDataID;
- return true;
- }
-
- if ("ReadDID" == literal) {
- *result = ReadDIDID;
- return true;
- }
-
- if ("GetDTCs" == literal) {
- *result = GetDTCsID;
- return true;
- }
-
- if ("ScrollableMessage" == literal) {
- *result = ScrollableMessageID;
- return true;
- }
-
- if ("Slider" == literal) {
- *result = SliderID;
- return true;
- }
-
- if ("ShowConstantTBT" == literal) {
- *result = ShowConstantTBTID;
- return true;
- }
-
- if ("AlertManeuver" == literal) {
- *result = AlertManeuverID;
- return true;
- }
-
- if ("UpdateTurnList" == literal) {
- *result = UpdateTurnListID;
- return true;
- }
-
- if ("ChangeRegistration" == literal) {
- *result = ChangeRegistrationID;
- return true;
- }
-
- if ("GenericResponse" == literal) {
- *result = GenericResponseID;
- return true;
- }
-
- if ("PutFile" == literal) {
- *result = PutFileID;
- return true;
- }
-
- if ("DeleteFile" == literal) {
- *result = DeleteFileID;
- return true;
- }
-
- if ("ListFiles" == literal) {
- *result = ListFilesID;
- return true;
- }
-
- if ("SetAppIcon" == literal) {
- *result = SetAppIconID;
- return true;
- }
-
- if ("SetDisplayLayout" == literal) {
- *result = SetDisplayLayoutID;
- return true;
- }
-
- if ("DiagnosticMessage" == literal) {
- *result = DiagnosticMessageID;
- return true;
- }
-
- if ("SystemRequest" == literal) {
- *result = SystemRequestID;
- return true;
- }
-
- if ("SendLocation" == literal) {
- *result = SendLocationID;
- return true;
- }
-
- if ("DialNumber" == literal) {
- *result = DialNumberID;
- return true;
- }
-
- if ("ButtonPress" == literal) {
- *result = ButtonPressID;
- return true;
- }
-
- if ("GetInteriorVehicleData" == literal) {
- *result = GetInteriorVehicleDataID;
- return true;
- }
-
- if ("SetInteriorVehicleData" == literal) {
- *result = SetInteriorVehicleDataID;
- return true;
- }
-
- if ("GetWayPoints" == literal) {
- *result = GetWayPointsID;
- return true;
- }
-
- if ("SubscribeWayPoints" == literal) {
- *result = SubscribeWayPointsID;
- return true;
- }
-
- if ("UnsubscribeWayPoints" == literal) {
- *result = UnsubscribeWayPointsID;
- return true;
- }
-
- if ("GetSystemCapability" == literal) {
- *result = GetSystemCapabilityID;
- return true;
- }
-
- if ("SendHapticData" == literal) {
- *result = SendHapticDataID;
- return true;
- }
-
- if ("SetCloudAppProperties" == literal) {
- *result = SetCloudAppPropertiesID;
- return true;
- }
-
- if ("GetCloudAppProperties" == literal) {
- *result = GetCloudAppPropertiesID;
- return true;
- }
-
- if ("PublishAppService" == literal) {
- *result = PublishAppServiceID;
- return true;
- }
-
- if ("GetFile" == literal) {
- *result = GetFileID;
- return true;
- }
-
- if ("GetAppServiceData" == literal) {
- *result = GetAppServiceDataID;
- return true;
- }
-
- if ("PerformAppServiceInteraction" == literal) {
- *result = PerformAppServiceInteractionID;
- return true;
- }
-
- if ("UnpublishAppService" == literal) {
- *result = UnpublishAppServiceID;
- return true;
- }
-
- if ("CloseApplication" == literal) {
- *result = CloseApplicationID;
- return true;
- }
-
- if ("ShowAppMenu" == literal) {
- *result = ShowAppMenuID;
- return true;
- }
-
- if ("OnHMIStatus" == literal) {
- *result = OnHMIStatusID;
- return true;
- }
-
- if ("OnAppInterfaceUnregistered" == literal) {
- *result = OnAppInterfaceUnregisteredID;
- return true;
- }
-
- if ("OnButtonEvent" == literal) {
- *result = OnButtonEventID;
- return true;
- }
-
- if ("OnButtonPress" == literal) {
- *result = OnButtonPressID;
- return true;
- }
-
- if ("OnVehicleData" == literal) {
- *result = OnVehicleDataID;
- return true;
- }
-
- if ("OnCommand" == literal) {
- *result = OnCommandID;
- return true;
- }
-
- if ("OnTBTClientState" == literal) {
- *result = OnTBTClientStateID;
- return true;
- }
-
- if ("OnDriverDistraction" == literal) {
- *result = OnDriverDistractionID;
- return true;
- }
-
- if ("OnPermissionsChange" == literal) {
- *result = OnPermissionsChangeID;
- return true;
- }
-
- if ("OnAudioPassThru" == literal) {
- *result = OnAudioPassThruID;
- return true;
- }
-
- if ("OnLanguageChange" == literal) {
- *result = OnLanguageChangeID;
- return true;
- }
-
- if ("OnKeyboardInput" == literal) {
- *result = OnKeyboardInputID;
- return true;
- }
-
- if ("OnTouchEvent" == literal) {
- *result = OnTouchEventID;
- return true;
- }
-
- if ("OnSystemRequest" == literal) {
- *result = OnSystemRequestID;
- return true;
- }
-
- if ("OnHashChange" == literal) {
- *result = OnHashChangeID;
- return true;
- }
-
- if ("OnInteriorVehicleData" == literal) {
- *result = OnInteriorVehicleDataID;
- return true;
- }
-
- if ("OnWayPointChange" == literal) {
- *result = OnWayPointChangeID;
- return true;
- }
-
- if ("OnRCStatus" == literal) {
- *result = OnRCStatusID;
- return true;
- }
-
- if ("OnAppServiceData" == literal) {
- *result = OnAppServiceDataID;
- return true;
- }
-
- if ("OnSystemCapabilityUpdated" == literal) {
- *result = OnSystemCapabilityUpdatedID;
- return true;
- }
-
- if ("EncodedSyncPData" == literal) {
- *result = EncodedSyncPDataID;
- return true;
- }
-
- if ("SyncPData" == literal) {
- *result = SyncPDataID;
- return true;
- }
-
- if ("OnEncodedSyncPData" == literal) {
- *result = OnEncodedSyncPDataID;
- return true;
- }
-
- if ("OnSyncPData" == literal) {
- *result = OnSyncPDataID;
- return true;
- }
- return false;
-};
-
const std::string kDefaultApp = "default";
const std::string kPreDataConsentApp = "pre_DataConsent";
const std::string kDeviceApp = "device";
diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc
index d39b3f7623..ca83f6e571 100644
--- a/src/components/policy/policy_external/src/policy_table/types.cc
+++ b/src/components/policy/policy_external/src/policy_table/types.cc
@@ -745,9 +745,60 @@ void Rpcs::SetPolicyTableType(PolicyTableType pt_type) {
disallowed_by_external_consent_entities_on.SetPolicyTableType(pt_type);
}
+// EndpointProperties methods
+EndpointProperty::EndpointProperty() : CompositeType(kUninitialized) {}
+
+EndpointProperty::~EndpointProperty() {}
+
+EndpointProperty::EndpointProperty(const Json::Value* value__)
+ : CompositeType(InitHelper(value__, &Json::Value::isObject))
+ , version(impl::ValueMember(value__, "version")) {}
+
+Json::Value EndpointProperty::ToJsonValue() const {
+ Json::Value result__(Json::objectValue);
+ impl::WriteJsonField("version", version, &result__);
+ return result__;
+}
+
+bool EndpointProperty::is_valid() const {
+ if (!version.is_valid()) {
+ return false;
+ }
+ return Validate();
+}
+
+bool EndpointProperty::is_initialized() const {
+ return (initialization_state__ != kUninitialized) || (!struct_empty());
+}
+
+bool EndpointProperty::struct_empty() const {
+ if (version.is_initialized()) {
+ return false;
+ }
+
+ return true;
+}
+
+void EndpointProperty::ReportErrors(rpc::ValidationReport* report__) const {
+ if (struct_empty()) {
+ rpc::CompositeType::ReportErrors(report__);
+ }
+ if (!version.is_valid()) {
+ version.ReportErrors(&report__->ReportSubobject("version"));
+ }
+}
+
+void EndpointProperty::SetPolicyTableType(PolicyTableType pt_type) {
+ CompositeType::SetPolicyTableType(pt_type);
+ version.SetPolicyTableType(pt_type);
+}
+
// ModuleConfig methods
ModuleConfig::ModuleConfig() : CompositeType(kUninitialized) {}
+const std::string ModuleConfig::kDefaultOemMappingServiceName =
+ "custom_vehicle_data_mapping_url";
+
ModuleConfig::ModuleConfig(
uint8_t exchange_after_x_ignition_cycles,
int64_t exchange_after_x_kilometers,
@@ -755,6 +806,7 @@ ModuleConfig::ModuleConfig(
uint16_t timeout_after_x_seconds,
const SecondsBetweenRetries& seconds_between_retries,
const ServiceEndpoints& endpoints,
+ const ServiceEndpointProperties& endpoint_properties,
const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority)
: CompositeType(kUninitialized)
, exchange_after_x_ignition_cycles(exchange_after_x_ignition_cycles)
@@ -763,6 +815,7 @@ ModuleConfig::ModuleConfig(
, timeout_after_x_seconds(timeout_after_x_seconds)
, seconds_between_retries(seconds_between_retries)
, endpoints(endpoints)
+ , endpoint_properties(endpoint_properties)
, notifications_per_minute_by_priority(
notifications_per_minute_by_priority) {}
@@ -780,6 +833,7 @@ ModuleConfig::ModuleConfig(const Json::Value* value__)
, seconds_between_retries(
impl::ValueMember(value__, "seconds_between_retries"))
, endpoints(impl::ValueMember(value__, "endpoints"))
+ , endpoint_properties(impl::ValueMember(value__, "endpoint_properties"))
, notifications_per_minute_by_priority(
impl::ValueMember(value__, "notifications_per_minute_by_priority"))
, vehicle_make(impl::ValueMember(value__, "vehicle_make"))
@@ -800,6 +854,7 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) {
timeout_after_x_seconds = from.timeout_after_x_seconds;
seconds_between_retries = from.seconds_between_retries;
endpoints = from.endpoints;
+ endpoint_properties = from.endpoint_properties;
notifications_per_minute_by_priority =
from.notifications_per_minute_by_priority;
lock_screen_dismissal_enabled = from.lock_screen_dismissal_enabled;
@@ -828,6 +883,7 @@ Json::Value ModuleConfig::ToJsonValue() const {
impl::WriteJsonField(
"seconds_between_retries", seconds_between_retries, &result__);
impl::WriteJsonField("endpoints", endpoints, &result__);
+ impl::WriteJsonField("endpoint_properties", endpoint_properties, &result__);
impl::WriteJsonField("notifications_per_minute_by_priority",
notifications_per_minute_by_priority,
&result__);
@@ -870,6 +926,9 @@ bool ModuleConfig::is_valid() const {
if (!endpoints.is_valid()) {
return false;
}
+ if (!endpoint_properties.is_valid()) {
+ return false;
+ }
if (!notifications_per_minute_by_priority.is_valid()) {
return false;
}
@@ -930,6 +989,10 @@ bool ModuleConfig::struct_empty() const {
return false;
}
+ if (endpoint_properties.is_initialized()) {
+ return false;
+ }
+
if (notifications_per_minute_by_priority.is_initialized()) {
return false;
}
@@ -986,6 +1049,10 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const {
if (!endpoints.is_valid()) {
endpoints.ReportErrors(&report__->ReportSubobject("endpoints"));
}
+ if (!endpoint_properties.is_valid()) {
+ endpoint_properties.ReportErrors(
+ &report__->ReportSubobject("endpoint_properties"));
+ }
if (!notifications_per_minute_by_priority.is_valid()) {
notifications_per_minute_by_priority.ReportErrors(
&report__->ReportSubobject("notifications_per_minute_by_priority"));
@@ -1051,6 +1118,7 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) {
timeout_after_x_seconds.SetPolicyTableType(pt_type);
seconds_between_retries.SetPolicyTableType(pt_type);
endpoints.SetPolicyTableType(pt_type);
+ endpoint_properties.SetPolicyTableType(pt_type);
notifications_per_minute_by_priority.SetPolicyTableType(pt_type);
lock_screen_dismissal_enabled.SetPolicyTableType(pt_type);
vehicle_make.SetPolicyTableType(pt_type);
@@ -2092,6 +2160,381 @@ void DeviceParams::SetPolicyTableType(PolicyTableType pt_type) {
connection_type.SetPolicyTableType(pt_type);
}
+// VehicleDataItem methods
+VehicleDataItem::VehicleDataItem() : CompositeType(kUninitialized) {}
+
+VehicleDataItem::VehicleDataItem(const VehicleDataItem& vehicle_data)
+ : CompositeType(vehicle_data.initialization_state__)
+ , name(vehicle_data.name)
+ , type(vehicle_data.type)
+ , key(vehicle_data.key)
+ , mandatory(vehicle_data.mandatory)
+ , params(vehicle_data.params)
+ , array(vehicle_data.array)
+ , since(vehicle_data.since)
+ , until(vehicle_data.until)
+ , removed(vehicle_data.removed)
+ , deprecated(vehicle_data.deprecated)
+ , minvalue(vehicle_data.minvalue)
+ , maxvalue(vehicle_data.maxvalue)
+ , minsize(vehicle_data.minsize)
+ , maxsize(vehicle_data.maxsize)
+ , minlength(vehicle_data.minlength)
+ , maxlength(vehicle_data.maxlength) {}
+
+VehicleDataItem::VehicleDataItem(const Json::Value* value__)
+ : CompositeType(InitHelper(value__, &Json::Value::isObject))
+ , name(impl::ValueMember(value__, "name"))
+ , type(impl::ValueMember(value__, "type"))
+ , key(impl::ValueMember(value__, "key"))
+ , mandatory(impl::ValueMember(value__, "mandatory"))
+ , params(impl::ValueMember(value__, "params"))
+ , array(impl::ValueMember(value__, "array"))
+ , since(impl::ValueMember(value__, "since"))
+ , until(impl::ValueMember(value__, "until"))
+ , removed(impl::ValueMember(value__, "removed"))
+ , deprecated(impl::ValueMember(value__, "deprecated"))
+ , minvalue(impl::ValueMember(value__, "minvalue"))
+ , maxvalue(impl::ValueMember(value__, "maxvalue"))
+ , minsize(impl::ValueMember(value__, "minsize"))
+ , maxsize(impl::ValueMember(value__, "maxsize"))
+ , minlength(impl::ValueMember(value__, "minlength"))
+ , maxlength(impl::ValueMember(value__, "maxlength")) {}
+
+VehicleDataItem::~VehicleDataItem() {}
+
+const std::string VehicleDataItem::kInteger = "Integer";
+const std::string VehicleDataItem::kStruct = "Struct";
+const std::string VehicleDataItem::kString = "String";
+const std::string VehicleDataItem::kFloat = "Float";
+const std::string VehicleDataItem::kBoolean = "Boolean";
+const std::string VehicleDataItem::kName = "name";
+const std::string VehicleDataItem::kParams = "params";
+
+const std::vector<std::string> VehicleDataItem::kPODTypes = {
+ kInteger, kFloat, kString, kBoolean};
+
+Json::Value VehicleDataItem::ToJsonValue() const {
+ Json::Value ret(Json::objectValue);
+ impl::WriteJsonField("name", name, &ret);
+ impl::WriteJsonField("type", type, &ret);
+ impl::WriteJsonField("key", key, &ret);
+ impl::WriteJsonField("array", array, &ret);
+ impl::WriteJsonField("mandatory", mandatory, &ret);
+ impl::WriteJsonField("params", params, &ret);
+ impl::WriteJsonField("since", since, &ret);
+ impl::WriteJsonField("until", until, &ret);
+ impl::WriteJsonField("removed", removed, &ret);
+ impl::WriteJsonField("deprecated", deprecated, &ret);
+ impl::WriteJsonField("minvalue", minvalue, &ret);
+ impl::WriteJsonField("maxvalue", maxvalue, &ret);
+ impl::WriteJsonField("minsize", minsize, &ret);
+ impl::WriteJsonField("maxsize", maxsize, &ret);
+ impl::WriteJsonField("minlength", minlength, &ret);
+ impl::WriteJsonField("maxlength", maxlength, &ret);
+ return ret;
+}
+
+bool VehicleDataItem::operator==(const VehicleDataItem& vd) {
+ return (name == vd.name && type == vd.type && key == vd.key &&
+ mandatory == vd.mandatory && params == vd.params &&
+ array == vd.array && since == vd.since && until == vd.until &&
+ removed == vd.removed && deprecated == vd.deprecated &&
+ minvalue == vd.minvalue && maxvalue == vd.maxvalue &&
+ minsize == vd.minsize && maxsize == vd.maxsize &&
+ minlength == vd.minlength && maxlength == vd.maxlength);
+}
+
+bool VehicleDataItem::is_valid() const {
+ if (!name.is_valid()) {
+ return false;
+ }
+ if (!type.is_valid()) {
+ return false;
+ }
+ if (!key.is_valid()) {
+ return false;
+ }
+ if (!array.is_valid()) {
+ return false;
+ }
+ if (!mandatory.is_valid()) {
+ return false;
+ }
+ if (!params.is_valid()) {
+ return false;
+ }
+ if (!since.is_valid()) {
+ return false;
+ }
+ if (!until.is_valid()) {
+ return false;
+ }
+ if (!removed.is_valid()) {
+ return false;
+ }
+ if (!deprecated.is_valid()) {
+ return false;
+ }
+ if (!minvalue.is_valid()) {
+ return false;
+ }
+ if (!maxvalue.is_valid()) {
+ return false;
+ }
+ if (!minsize.is_valid()) {
+ return false;
+ }
+ if (!maxsize.is_valid()) {
+ return false;
+ }
+ if (!minlength.is_valid()) {
+ return false;
+ }
+ if (!maxlength.is_valid()) {
+ return false;
+ }
+ return Validate();
+}
+
+bool VehicleDataItem::is_initialized() const {
+ return (initialization_state__ != kUninitialized) || (struct_not_empty());
+}
+
+bool VehicleDataItem::struct_not_empty() const {
+ if (!name.is_initialized()) {
+ return false;
+ }
+ if (!type.is_initialized()) {
+ return false;
+ }
+ if (!key.is_initialized()) {
+ return false;
+ }
+ if (!array.is_initialized()) {
+ return false;
+ }
+ if (!mandatory.is_initialized()) {
+ return false;
+ }
+ if (!params.is_initialized()) {
+ return false;
+ }
+ if (!since.is_initialized()) {
+ return false;
+ }
+ if (!until.is_initialized()) {
+ return false;
+ }
+ if (!removed.is_initialized()) {
+ return false;
+ }
+ if (!deprecated.is_initialized()) {
+ return false;
+ }
+ if (!minvalue.is_initialized()) {
+ return false;
+ }
+ if (!maxvalue.is_initialized()) {
+ return false;
+ }
+ if (!minsize.is_initialized()) {
+ return false;
+ }
+ if (!maxsize.is_initialized()) {
+ return false;
+ }
+ if (!minlength.is_initialized()) {
+ return false;
+ }
+ if (!maxlength.is_initialized()) {
+ return false;
+ }
+ return true;
+}
+
+void VehicleDataItem::ReportErrors(rpc::ValidationReport* report__) const {
+ if (!struct_not_empty()) {
+ rpc::CompositeType::ReportErrors(report__);
+ }
+ if (!name.is_valid()) {
+ name.ReportErrors(&report__->ReportSubobject("name"));
+ }
+ if (!type.is_valid()) {
+ type.ReportErrors(&report__->ReportSubobject("type"));
+ }
+ if (type.is_initialized() && !ValidateTypes()) {
+ report__->set_validation_info("Unknown type [" + std::string(name) +
+ "]: '" + std::string(type) + "'.");
+ }
+ if (!key.is_valid()) {
+ key.ReportErrors(&report__->ReportSubobject("key"));
+ }
+ if (!array.is_valid()) {
+ array.ReportErrors(&report__->ReportSubobject("array"));
+ }
+ if (!mandatory.is_valid()) {
+ mandatory.ReportErrors(&report__->ReportSubobject("mandatory"));
+ }
+ if (!params.is_valid()) {
+ params.ReportErrors(&report__->ReportSubobject("params"));
+ }
+ if (!since.is_valid()) {
+ since.ReportErrors(&report__->ReportSubobject("since"));
+ }
+ if (!until.is_valid()) {
+ until.ReportErrors(&report__->ReportSubobject("until"));
+ }
+ if (!removed.is_valid()) {
+ removed.ReportErrors(&report__->ReportSubobject("removed"));
+ }
+ if (!deprecated.is_valid()) {
+ deprecated.ReportErrors(&report__->ReportSubobject("deprecated"));
+ }
+ if (!minvalue.is_valid()) {
+ minvalue.ReportErrors(&report__->ReportSubobject("minvalue"));
+ }
+ if (!maxvalue.is_valid()) {
+ maxvalue.ReportErrors(&report__->ReportSubobject("maxvalue"));
+ }
+ if (!minsize.is_valid()) {
+ minsize.ReportErrors(&report__->ReportSubobject("minsize"));
+ }
+ if (!minlength.is_valid()) {
+ minlength.ReportErrors(&report__->ReportSubobject("minlength"));
+ }
+ if (!maxlength.is_valid()) {
+ maxlength.ReportErrors(&report__->ReportSubobject("maxlength"));
+ }
+}
+
+void VehicleDataItem::SetPolicyTableType(PolicyTableType pt_type) {
+ CompositeType::SetPolicyTableType(pt_type);
+ name.SetPolicyTableType(pt_type);
+ type.SetPolicyTableType(pt_type);
+ key.SetPolicyTableType(pt_type);
+ array.SetPolicyTableType(pt_type);
+ mandatory.SetPolicyTableType(pt_type);
+ params.SetPolicyTableType(pt_type);
+ since.SetPolicyTableType(pt_type);
+ until.SetPolicyTableType(pt_type);
+ removed.SetPolicyTableType(pt_type);
+ deprecated.SetPolicyTableType(pt_type);
+ minvalue.SetPolicyTableType(pt_type);
+ maxvalue.SetPolicyTableType(pt_type);
+ minsize.SetPolicyTableType(pt_type);
+ maxsize.SetPolicyTableType(pt_type);
+ minlength.SetPolicyTableType(pt_type);
+ maxlength.SetPolicyTableType(pt_type);
+}
+
+bool VehicleDataItem::ValidateTypes() const {
+ if (IsPrimitiveType() || NULL != EnumSchemaItemFactory::Get(type)) {
+ // params should be empty for POD types
+ // and for enum values, generated from API
+ return (!(params.is_initialized()) || params->empty());
+ }
+
+ if ("Struct" == std::string(type)) {
+ return params.is_initialized() && !(params->empty()) && params.is_valid();
+ }
+ return false;
+}
+
+bool VehicleDataItem::IsPrimitiveType() const {
+ return helpers::in_range(kPODTypes, std::string(type));
+}
+
+// VehicleData methods
+VehicleData::VehicleData() : CompositeType(kUninitialized) {}
+
+VehicleData::VehicleData(const VehicleData& vehicle_data)
+ : CompositeType(vehicle_data.initialization_state__)
+ , schema_version(vehicle_data.schema_version)
+ , schema_items(vehicle_data.schema_items) {}
+
+VehicleData::VehicleData(const Json::Value* value__)
+ : CompositeType(InitHelper(value__, &Json::Value::isObject))
+ , schema_version(impl::ValueMember(value__, "schema_version"))
+ , schema_items(impl::ValueMember(value__, "schema_items")) {}
+
+VehicleData::~VehicleData() {}
+
+bool VehicleData::is_valid() const {
+ if (!schema_version.is_valid()) {
+ return false;
+ }
+ if (!schema_items.is_valid()) {
+ return false;
+ }
+ return Validate();
+}
+
+bool VehicleData::is_initialized() const {
+ return (initialization_state__ != kUninitialized) || (!struct_empty());
+}
+
+bool VehicleData::struct_empty() const {
+ if (schema_version.is_initialized()) {
+ return false;
+ }
+ if (schema_items.is_initialized()) {
+ return false;
+ }
+ return true;
+}
+
+Json::Value VehicleData::ToJsonValue() const {
+ Json::Value ret(Json::objectValue);
+ impl::WriteJsonField("schema_version", schema_version, &ret);
+ impl::WriteJsonField("schema_items", schema_items, &ret);
+ return ret;
+}
+
+void VehicleData::ReportErrors(rpc::ValidationReport* report__) const {
+ if (struct_empty()) {
+ rpc::CompositeType::ReportErrors(report__);
+ }
+ const auto pt_type = GetPolicyTableType();
+ const auto pt_type_str = PolicyTableTypeToString(pt_type);
+ std::string validation_info = "";
+
+ if (PT_SNAPSHOT == pt_type) {
+ if (schema_items.is_initialized()) {
+ validation_info +=
+ "; schema_items " + omitted_validation_info + pt_type_str;
+ }
+ if (!schema_version.is_initialized()) {
+ validation_info +=
+ "; schema_version " + required_validation_info + pt_type_str;
+ }
+ report__->set_validation_info(validation_info);
+ }
+ if (PT_UPDATE == pt_type || PT_PRELOADED == pt_type) {
+ if ((schema_version.is_initialized() && !schema_items.is_initialized()) ||
+ (!schema_version.is_initialized() && schema_items.is_initialized())) {
+ validation_info +=
+ "; if schema_version exist, schema_items should "
+ "also exist in " +
+ pt_type_str;
+ }
+ report__->set_validation_info(validation_info);
+ }
+
+ if (!schema_version.is_valid()) {
+ schema_version.ReportErrors(&report__->ReportSubobject("schema_version"));
+ }
+ if (!schema_items.is_valid()) {
+ schema_items.ReportErrors(&report__->ReportSubobject("schema_items"));
+ }
+}
+
+void VehicleData::SetPolicyTableType(PolicyTableType pt_type) {
+ CompositeType::SetPolicyTableType(pt_type);
+ schema_version.SetPolicyTableType(pt_type);
+ schema_items.SetPolicyTableType(pt_type);
+}
+
// PolicyTable methods
PolicyTable::PolicyTable() : CompositeType(kUninitialized) {}
@@ -2118,7 +2561,8 @@ PolicyTable::PolicyTable(const Json::Value* value__)
, module_meta(impl::ValueMember(value__, "module_meta"))
, usage_and_error_counts(
impl::ValueMember(value__, "usage_and_error_counts"))
- , device_data(impl::ValueMember(value__, "device_data")) {}
+ , device_data(impl::ValueMember(value__, "device_data"))
+ , vehicle_data(impl::ValueMember(value__, "vehicle_data")) {}
Json::Value PolicyTable::ToJsonValue() const {
Json::Value result__(Json::objectValue);
@@ -2131,6 +2575,7 @@ Json::Value PolicyTable::ToJsonValue() const {
impl::WriteJsonField(
"usage_and_error_counts", usage_and_error_counts, &result__);
impl::WriteJsonField("device_data", device_data, &result__);
+ impl::WriteJsonField("vehicle_data", vehicle_data, &result__);
return result__;
}
@@ -2156,6 +2601,9 @@ bool PolicyTable::is_valid() const {
if (!device_data.is_valid()) {
return false;
}
+ if (!vehicle_data.is_valid()) {
+ return false;
+ }
return Validate();
}
@@ -2188,6 +2636,10 @@ bool PolicyTable::struct_empty() const {
if (device_data.is_initialized()) {
return false;
}
+
+ if (vehicle_data.is_initialized()) {
+ return false;
+ }
return true;
}
@@ -2230,6 +2682,9 @@ void PolicyTable::ReportErrors(rpc::ValidationReport* report__) const {
if (!device_data.is_valid()) {
device_data.ReportErrors(&report__->ReportSubobject("device_data"));
}
+ if (!vehicle_data.is_valid()) {
+ vehicle_data.ReportErrors(&report__->ReportSubobject("vehicle_data"));
+ }
}
void PolicyTable::SetPolicyTableType(PolicyTableType pt_type) {
@@ -2241,6 +2696,7 @@ void PolicyTable::SetPolicyTableType(PolicyTableType pt_type) {
module_meta.SetPolicyTableType(pt_type);
usage_and_error_counts.SetPolicyTableType(pt_type);
device_data.SetPolicyTableType(pt_type);
+ vehicle_data.SetPolicyTableType(pt_type);
}
// Table methods
diff --git a/src/components/policy/policy_external/src/policy_table/validation.cc b/src/components/policy/policy_external/src/policy_table/validation.cc
index f9c3f82793..c079a84dce 100644
--- a/src/components/policy/policy_external/src/policy_table/validation.cc
+++ b/src/components/policy/policy_external/src/policy_table/validation.cc
@@ -221,6 +221,15 @@ bool RpcParameters::Validate() const {
bool Rpcs::Validate() const {
return true;
}
+
+bool EndpointProperty::Validate() const {
+ if (!version.is_valid()) {
+ return false;
+ }
+
+ return true;
+}
+
bool ModuleConfig::Validate() const {
switch (GetPolicyTableType()) {
case PT_PRELOADED: {
@@ -258,6 +267,14 @@ bool ModuleConfig::Validate() const {
}
}
+ if (endpoint_properties.is_initialized()) {
+ const auto& endpoint_property =
+ endpoint_properties->find(kDefaultOemMappingServiceName);
+ if (endpoint_properties->end() != endpoint_property) {
+ return (*endpoint_property).second.version.is_initialized();
+ }
+ }
+
return true;
}
@@ -304,6 +321,32 @@ bool ConsentRecords::Validate() const {
bool DeviceParams::Validate() const {
return true;
}
+
+bool VehicleDataItem::Validate() const {
+ if (!ValidateTypes()) {
+ LOG4CXX_ERROR(
+ logger_,
+ "Unknown type: " << std::string(type) << " of " << std::string(key));
+ return false;
+ }
+ return true;
+}
+
+bool VehicleData::Validate() const {
+ const PolicyTableType policy_table_type = GetPolicyTableType();
+ bool result = true;
+ if (PT_SNAPSHOT == policy_table_type) {
+ result =
+ (!schema_items.is_initialized()) && schema_version.is_initialized();
+ }
+ if (PT_UPDATE == policy_table_type || PT_PRELOADED == policy_table_type) {
+ result =
+ (schema_version.is_initialized() && schema_items.is_initialized()) ||
+ (!schema_version.is_initialized() && !schema_items.is_initialized());
+ }
+ return result;
+}
+
bool PolicyTable::Validate() const {
PolicyTableType policy_table_type = GetPolicyTableType();
diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc
index b5786f1ad5..2f13ae3aaf 100644
--- a/src/components/policy/policy_external/src/sql_pt_queries.cc
+++ b/src/components/policy/policy_external/src/sql_pt_queries.cc
@@ -472,8 +472,7 @@ const std::string kCreateSchema =
" `minsize` INTEGER, "
" `maxsize` INTEGER, "
" `minlength` INTEGER, "
- " `maxlength` INTEGER, "
- " PRIMARY KEY(`name`,`key`) "
+ " `maxlength` INTEGER "
"); "
"CREATE TABLE IF NOT EXISTS `vehicle_data_item_parameters`( "
" `parent_name` VARCHAR(255) NOT NULL, "
@@ -692,13 +691,24 @@ const std::string kSelectVehicleDataItem =
"SELECT * FROM `vehicle_data_item_definition` "
"WHERE `key` = ? AND `name` = ?";
+const std::string kSelectVehicleDataItemWithVersion =
+ "SELECT * FROM `vehicle_data_item_definition` "
+ "WHERE `name` IS ? AND `key` IS ? AND `since` IS ? AND `until` IS ?";
+
const std::string kSelectVehicleDataItemParams =
"SELECT * FROM `vehicle_data_item_parameters` "
"WHERE `parent_name` = ? AND `parent_key` = ?";
const std::string kSelectParametrizedVehicleDataItemsKey =
"SELECT DISTINCT `parent_name`, `parent_key` FROM "
- "`vehicle_data_item_parameters`";
+ "`vehicle_data_item_parameters` "
+ "LEFT JOIN "
+ "(SELECT DISTINCT `param_name`, `param_key` FROM "
+ "`vehicle_data_item_parameters`) `vdi_params` ON "
+ "`vehicle_data_item_parameters`.`parent_name` = `vdi_params`.`param_name` "
+ "AND "
+ "`vehicle_data_item_parameters`.`parent_key` = `vdi_params`.`param_key` "
+ "WHERE `vdi_params`.`param_key` IS NULL";
const std::string kSelectNonParametrizedVehicleDataItems =
"SELECT * FROM `vehicle_data_item_definition` "
@@ -707,7 +717,8 @@ const std::string kSelectNonParametrizedVehicleDataItems =
"UNION "
"SELECT `param_name`, `param_key` FROM `vehicle_data_item_parameters`) "
"`vdi_params` ON "
- "`vehicle_data_item_definition`.`name` = `vdi_params`.`parent_name` AND "
+ "`vehicle_data_item_definition`.`name` = `vdi_params`.`parent_name` "
+ "AND "
"`vehicle_data_item_definition`.`key` = `vdi_params`.`parent_key` "
"WHERE `vdi_params`.`parent_key` IS NULL";
diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc
index f69a64a6a0..8abe37b9ea 100644
--- a/src/components/policy/policy_external/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_external/src/sql_pt_representation.cc
@@ -515,6 +515,11 @@ std::shared_ptr<policy_table::Table> SQLPTRepresentation::GenerateSnapshot()
GatherConsumerFriendlyMessages(
&*table->policy_table.consumer_friendly_messages);
GatherApplicationPoliciesSection(&table->policy_table.app_policies_section);
+ GatherVehicleData(&*table->policy_table.vehicle_data);
+ if (!table->policy_table.vehicle_data.is_initialized()) {
+ rpc::Optional<rpc::String<0, 100> > null_version;
+ table->policy_table.vehicle_data->schema_version = null_version;
+ }
return table;
}
@@ -559,6 +564,18 @@ void SQLPTRepresentation::GatherModuleConfig(
}
}
+ utils::dbms::SQLQuery endpoint_properties(db());
+ if (!endpoint_properties.Prepare(sql_pt::kSelectEndpointProperties)) {
+ LOG4CXX_ERROR(logger_, "Incorrect statement for Endpoint properties");
+ } else {
+ while (endpoint_properties.Next()) {
+ const std::string& service = endpoint_properties.GetString(0);
+ const std::string& version = endpoint_properties.GetString(1);
+ auto& ep_properties = (*config->endpoint_properties);
+ *ep_properties[service].version = version;
+ }
+ }
+
utils::dbms::SQLQuery notifications(db());
if (!notifications.Prepare(sql_pt::kSelectNotificationsPerMin)) {
LOG4CXX_WARN(logger_, "Incorrect select statement for notifications");
@@ -650,16 +667,15 @@ bool SQLPTRepresentation::GatherFunctionalGroupings(
}
}
if (!rpcs.IsNull(2)) {
- policy_table::Parameter param;
- if (policy_table::EnumFromJsonString(rpcs.GetString(2), &param)) {
- // EMPTY is a special mark to specify that 'parameters' section is
- // present, but has no parameters. It is not valid parameter value.
- if (policy_table::P_EMPTY == param) {
- (*rpcs_tbl.rpcs[rpcs.GetString(0)].parameters).mark_initialized();
- continue;
- }
- InsertUnique(param, &(*rpcs_tbl.rpcs[rpcs.GetString(0)].parameters));
+ std::string param = rpcs.GetString(2);
+ // EMPTY is a special mark to specify that 'parameters' section is
+ // present, but has no parameters. It is not valid parameter value.
+ if ("EMPTY" == param) {
+ (*rpcs_tbl.rpcs[rpcs.GetString(0)].parameters).mark_initialized();
+ continue;
}
+ InsertUnique(rpcs.GetString(2),
+ &(*rpcs_tbl.rpcs[rpcs.GetString(0)].parameters));
}
}
@@ -814,6 +830,43 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection(
return true;
}
+bool SQLPTRepresentation::GatherVehicleData(
+ policy_table::VehicleData* vehicle_data) const {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kSelectVehicleDataSchemaVersion) ||
+ !query.Next()) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrect statement for vehicle data schema version");
+ return false;
+ }
+ *vehicle_data->schema_version = query.GetString(0);
+
+ vehicle_data->mark_initialized();
+ return GatherVehicleDataItems(&*vehicle_data->schema_items);
+}
+
+bool SQLPTRepresentation::GatherVehicleDataItems(
+ policy_table::VehicleDataItems* vehicle_data_items) const {
+ auto parameterized_vdi = SelectParameterizedVehicleDataItems();
+ if (!parameterized_vdi.is_initialized()) {
+ return false;
+ }
+
+ auto non_parameterized_vdi = SelectNonParameterizedVehicleDataItems();
+ if (!non_parameterized_vdi.is_initialized()) {
+ return false;
+ }
+
+ vehicle_data_items->insert(vehicle_data_items->end(),
+ parameterized_vdi.begin(),
+ parameterized_vdi.end());
+ vehicle_data_items->insert(vehicle_data_items->end(),
+ non_parameterized_vdi.begin(),
+ non_parameterized_vdi.end());
+
+ return true;
+}
+
bool SQLPTRepresentation::Save(const policy_table::Table& table) {
LOG4CXX_AUTO_TRACE(logger_);
db_->BeginTransaction();
@@ -848,6 +901,10 @@ bool SQLPTRepresentation::Save(const policy_table::Table& table) {
db_->RollbackTransaction();
return false;
}
+ if (!SaveVehicleData(*table.policy_table.vehicle_data)) {
+ db_->RollbackTransaction();
+ return false;
+ }
db_->CommitTransaction();
return true;
}
@@ -946,8 +1003,7 @@ bool SQLPTRepresentation::SaveRpcs(int64_t group_id,
query_parameter.Bind(0, it->first);
query_parameter.Bind(
1, std::string(policy_table::EnumToJsonString(*hmi_it)));
- query_parameter.Bind(
- 2, std::string(policy_table::EnumToJsonString(*ps_it)));
+ query_parameter.Bind(2, std::string(*ps_it));
query_parameter.Bind(3, group_id);
if (!query_parameter.Exec() || !query_parameter.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into rpc with parameter");
@@ -1161,6 +1217,43 @@ bool policy::SQLPTRepresentation::SaveDevicePolicy(
return true;
}
+bool SQLPTRepresentation::SaveVehicleDataItems(
+ const policy_table::VehicleDataItems& vehicle_data_items) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ DeleteVehicleDataItems();
+ for (const auto& item : vehicle_data_items) {
+ if (!InsertVehicleDataItem(item)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool SQLPTRepresentation::SaveVehicleData(
+ const policy_table::VehicleData& vehicle_data) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (!vehicle_data.is_initialized() ||
+ !vehicle_data.schema_items.is_initialized() ||
+ !vehicle_data.schema_version.is_initialized()) {
+ LOG4CXX_DEBUG(logger_, "Vehicle data is absent in policy table.");
+ return true;
+ }
+
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kInsertVehicleDataSchemaVersion)) {
+ LOG4CXX_WARN(logger_,
+ "Incorrect insert of schema_version to vehicle_data.");
+ return false;
+ }
+ query.Bind(0, *vehicle_data.schema_version);
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Failed to insert schema_version to vehicle_data.");
+ return false;
+ }
+
+ return SaveVehicleDataItems(*vehicle_data.schema_items);
+}
+
bool SQLPTRepresentation::SaveAppGroup(
const std::string& app_id, const policy_table::Strings& app_groups) {
utils::dbms::SQLQuery query(db());
@@ -1427,6 +1520,10 @@ bool SQLPTRepresentation::SaveModuleConfig(
return false;
}
+ if (!SaveServiceEndpointProperties(*config.endpoint_properties)) {
+ return false;
+ }
+
return true;
}
@@ -1465,6 +1562,31 @@ bool SQLPTRepresentation::SaveServiceEndpoints(
return true;
}
+bool SQLPTRepresentation::SaveServiceEndpointProperties(
+ const policy_table::ServiceEndpointProperties& endpoint_properties) {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kInsertEndpointVersion)) {
+ LOG4CXX_WARN(
+ logger_,
+ "Incorrect insert of endpoint property to endpoint_properties.");
+ return false;
+ }
+
+ for (auto& endpoint_property : endpoint_properties) {
+ query.Bind(0, endpoint_property.first);
+ query.Bind(1, endpoint_property.second.version);
+
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(
+ logger_,
+ "Failed to insert endpoint property into endpoint_properties.");
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool SQLPTRepresentation::SaveConsumerFriendlyMessages(
const policy_table::ConsumerFriendlyMessages& messages) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -1551,6 +1673,123 @@ bool SQLPTRepresentation::SaveLanguage(const std::string& code) {
return true;
}
+policy_table::VehicleDataItem SQLPTRepresentation::PopulateVDIFromQuery(
+ const utils::dbms::SQLQuery& query) const {
+ policy_table::VehicleDataItem result;
+
+ result.name = query.GetString(0);
+ result.type = query.GetString(1);
+ result.key = query.GetString(2);
+ result.mandatory = query.GetBoolean(3);
+
+ if (!query.IsNull(4)) {
+ *result.array = query.GetBoolean(4);
+ }
+ if (!query.IsNull(5)) {
+ *result.since = query.GetString(5);
+ }
+ if (!query.IsNull(6)) {
+ *result.until = query.GetString(6);
+ }
+ if (!query.IsNull(7)) {
+ *result.removed = query.GetBoolean(7);
+ }
+ if (!query.IsNull(8)) {
+ *result.deprecated = query.GetBoolean(8);
+ }
+ if (!query.IsNull(9)) {
+ *result.minvalue = query.GetInteger(9);
+ }
+ if (!query.IsNull(10)) {
+ *result.maxvalue = query.GetInteger(10);
+ }
+ if (!query.IsNull(11)) {
+ *result.minsize = query.GetUInteger(11);
+ }
+ if (!query.IsNull(12)) {
+ *result.maxsize = query.GetUInteger(12);
+ }
+ if (!query.IsNull(13)) {
+ *result.minlength = query.GetUInteger(13);
+ }
+ if (!query.IsNull(14)) {
+ *result.maxlength = query.GetUInteger(14);
+ }
+ result.params->mark_initialized();
+
+ result.mark_initialized();
+ return result;
+}
+
+policy_table::VehicleDataItems
+SQLPTRepresentation::SelectParameterizedVehicleDataItems() const {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kSelectParametrizedVehicleDataItemsKey)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrect statement for parameterized vehicle data items");
+ return policy_table::VehicleDataItems();
+ }
+
+ policy_table::VehicleDataItems result;
+ result.mark_initialized();
+
+ while (query.Next()) {
+ const auto vdi = GetVehicleDataItem(query.GetString(0), query.GetString(1));
+ if (!vdi.is_initialized()) {
+ return policy_table::VehicleDataItems();
+ }
+ for (const auto& item : vdi) {
+ result.push_back(item);
+ }
+ }
+
+ return result;
+}
+
+policy_table::VehicleDataItems
+SQLPTRepresentation::SelectNonParameterizedVehicleDataItems() const {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kSelectNonParametrizedVehicleDataItems)) {
+ LOG4CXX_ERROR(
+ logger_,
+ "Incorrect statement for non parameterized vehicle data items");
+ return policy_table::VehicleDataItems();
+ }
+
+ auto result = policy_table::VehicleDataItems();
+ result.mark_initialized();
+
+ while (query.Next()) {
+ const auto vdi = PopulateVDIFromQuery(query);
+ if (!vdi.is_initialized()) {
+ return policy_table::VehicleDataItems();
+ }
+ result.push_back(vdi);
+ }
+ return result;
+}
+
+bool SQLPTRepresentation::DeleteVehicleDataItems() const {
+ utils::dbms::SQLQuery query(db());
+ db_->BeginTransaction();
+ if (!query.Exec(sql_pt::kDeleteVehicleDataItems)) {
+ LOG4CXX_ERROR(logger_,
+ "Failed clearing database: " << query.LastError().text());
+ db_->RollbackTransaction();
+ return false;
+ }
+
+ if (!query.Exec(sql_pt::kDeleteVehicleDataItemParams)) {
+ LOG4CXX_ERROR(logger_,
+ "Failed clearing database: " << query.LastError().text());
+ db_->RollbackTransaction();
+ return false;
+ }
+ db_->CommitTransaction();
+
+ return true;
+}
+
bool SQLPTRepresentation::SaveMessageString(
const std::string& type,
const std::string& lang,
@@ -2282,6 +2521,190 @@ bool SQLPTRepresentation::UpdateDBVersion() const {
return true;
}
+policy_table::VehicleDataItems SQLPTRepresentation::GetVehicleDataItem(
+ const std::string& name, const std::string& key) const {
+ policy_table::VehicleDataItems result;
+ utils::dbms::SQLQuery query(db());
+
+ if (!query.Prepare(sql_pt::kSelectVehicleDataItem)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrent select statement of vehicle data item. "
+ << query.LastError().text());
+ return result;
+ }
+
+ query.Bind(0, key);
+ query.Bind(1, name);
+
+ while (query.Next()) {
+ auto vdi = PopulateVDIFromQuery(query);
+ if (!vdi.is_initialized()) {
+ return policy_table::VehicleDataItems();
+ }
+
+ utils::dbms::SQLQuery param_query(db());
+ if (policy_table::VehicleDataItem::kStruct ==
+ static_cast<std::string>(vdi.type)) {
+ if (!param_query.Prepare(sql_pt::kSelectVehicleDataItemParams)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrent select statement of vehicle data item. "
+ << param_query.LastError().text());
+ return policy_table::VehicleDataItems();
+ }
+
+ param_query.Bind(0, name);
+ param_query.Bind(1, key);
+
+ while (param_query.Next()) {
+ const auto param_with_diff_versions = GetVehicleDataItem(
+ param_query.GetString(2), param_query.GetString(3));
+ if (!param_with_diff_versions.is_initialized()) {
+ return policy_table::VehicleDataItems();
+ }
+ for (const auto& param : param_with_diff_versions) {
+ vdi.params->push_back(param);
+ }
+ }
+ }
+ result.push_back(vdi);
+ }
+ if (!result.empty()) {
+ result.mark_initialized();
+ }
+
+ return result;
+}
+
+bool SQLPTRepresentation::InsertVehicleDataItem(
+ const policy_table::VehicleDataItem& vehicle_data_item) {
+ utils::dbms::SQLQuery query(db());
+
+ if (!vehicle_data_item.is_initialized() || !vehicle_data_item.is_valid()) {
+ LOG4CXX_ERROR(logger_, "Vehicle data item is not initialized.");
+ return false;
+ }
+
+ if (VehicleDataItemExists(vehicle_data_item)) {
+ LOG4CXX_INFO(logger_,
+ static_cast<std::string>(vehicle_data_item.key)
+ << " is already stored.");
+ return true;
+ }
+
+ if (!query.Prepare(sql_pt::kInsertVehicleDataItem)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrent select statement of vehicle data item. "
+ << query.LastError().text());
+ return false;
+ }
+
+ query.Bind(0, vehicle_data_item.name);
+ query.Bind(1, vehicle_data_item.type);
+ query.Bind(2, vehicle_data_item.key);
+ query.Bind(3, vehicle_data_item.mandatory);
+ vehicle_data_item.array.is_initialized()
+ ? query.Bind(4, *vehicle_data_item.array)
+ : query.Bind(4);
+ vehicle_data_item.since.is_initialized()
+ ? query.Bind(5, *vehicle_data_item.since)
+ : query.Bind(5);
+ vehicle_data_item.until.is_initialized()
+ ? query.Bind(6, *vehicle_data_item.until)
+ : query.Bind(6);
+ vehicle_data_item.removed.is_initialized()
+ ? query.Bind(7, *vehicle_data_item.removed)
+ : query.Bind(7);
+ vehicle_data_item.deprecated.is_initialized()
+ ? query.Bind(8, *vehicle_data_item.deprecated)
+ : query.Bind(8);
+ vehicle_data_item.minvalue.is_initialized()
+ ? query.Bind(9, *vehicle_data_item.minvalue)
+ : query.Bind(9);
+ vehicle_data_item.maxvalue.is_initialized()
+ ? query.Bind(10, *vehicle_data_item.maxvalue)
+ : query.Bind(10);
+ vehicle_data_item.minsize.is_initialized()
+ ? query.Bind(11, static_cast<int64_t>(*vehicle_data_item.minsize))
+ : query.Bind(11);
+ vehicle_data_item.maxsize.is_initialized()
+ ? query.Bind(12, static_cast<int64_t>(*vehicle_data_item.maxsize))
+ : query.Bind(12);
+ vehicle_data_item.minlength.is_initialized()
+ ? query.Bind(13, static_cast<int64_t>(*vehicle_data_item.minlength))
+ : query.Bind(13);
+ vehicle_data_item.maxlength.is_initialized()
+ ? query.Bind(14, static_cast<int64_t>(*vehicle_data_item.maxlength))
+ : query.Bind(14);
+
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_ERROR(logger_,
+ "Failed to insert vehicle data item: "
+ << static_cast<std::string>(vehicle_data_item.key)
+ << ". Error: " << query.LastError().text());
+ return false;
+ }
+
+ if (vehicle_data_item.params->is_initialized()) {
+ for (const auto& param : *(vehicle_data_item.params)) {
+ if (!InsertVehicleDataItem(param)) {
+ return false;
+ }
+
+ if (!query.Prepare(sql_pt::kInsertVehicleDataItemParams)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrent select statement of vehicle data item. "
+ << query.LastError().text());
+ return false;
+ }
+
+ query.Bind(0, vehicle_data_item.name);
+ query.Bind(1, vehicle_data_item.key);
+ query.Bind(2, param.name);
+ query.Bind(3, param.key);
+
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_ERROR(
+ logger_,
+ "Failed to insert to vehicle data item relations helper table: "
+ << static_cast<std::string>(param.key)
+ << ". Error: " << query.LastError().text());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool SQLPTRepresentation::VehicleDataItemExists(
+ const policy_table::VehicleDataItem& vehicle_data_item) const {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kSelectVehicleDataItemWithVersion)) {
+ LOG4CXX_ERROR(logger_,
+ "Incorrent select statement for vehicle data item. "
+ << query.LastError().text());
+ return false;
+ }
+
+ query.Bind(0, vehicle_data_item.name);
+ query.Bind(1, vehicle_data_item.key);
+ vehicle_data_item.since.is_initialized()
+ ? query.Bind(2, std::string(*vehicle_data_item.since))
+ : query.Bind(2);
+ vehicle_data_item.until.is_initialized()
+ ? query.Bind(3, std::string(*vehicle_data_item.until))
+ : query.Bind(3);
+
+ if (!query.Exec()) {
+ LOG4CXX_ERROR(logger_,
+ "Failed to retrieve vehicle data item: "
+ << std::string(vehicle_data_item.key)
+ << ". Error: " << query.LastError().text());
+ return false;
+ }
+ return !query.IsNull(0);
+}
+
const int32_t SQLPTRepresentation::GetDBVersion() const {
return utils::Djb2HashFromString(sql_pt::kCreateSchema);
}
diff --git a/src/components/policy/policy_external/test/include/policy/policy_manager_impl_test_base.h b/src/components/policy/policy_external/test/include/policy/policy_manager_impl_test_base.h
index 65972e0a82..6716cb71e2 100644
--- a/src/components/policy/policy_external/test/include/policy/policy_manager_impl_test_base.h
+++ b/src/components/policy/policy_external/test/include/policy/policy_manager_impl_test_base.h
@@ -112,7 +112,7 @@ class PolicyManagerImplTest : public ::testing::Test {
const std::string unpaired_device_id_;
PolicyManagerImpl* policy_manager_;
- MockCacheManagerInterface* cache_manager_;
+ NiceMock<MockCacheManagerInterface>* cache_manager_;
MockUpdateStatusManager update_manager_;
NiceMock<MockPolicyListener> listener_;
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 280dcf1fa7..b42b01c020 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
@@ -895,14 +895,19 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetInvalidUpdatePT_PTIsNotLoaded) {
std::string json = table.toStyledString();
::policy::BinaryMessage msg(json.begin(), json.end());
+ auto pt = std::make_shared<policy_table::Table>();
+ *pt = update;
+
// Assert
- EXPECT_CALL(*cache_manager_, GenerateSnapshot()).Times(0);
+ EXPECT_CALL(*cache_manager_, GenerateSnapshot()).WillOnce(Return(pt));
EXPECT_CALL(*cache_manager_, ApplyUpdate(_)).Times(0);
EXPECT_CALL(listener_, GetAppName(_)).Times(0);
EXPECT_CALL(listener_, OnUpdateStatusChanged(_)).Times(1);
EXPECT_CALL(*cache_manager_, SaveUpdateRequired(false)).Times(0);
EXPECT_CALL(*cache_manager_, TimeoutResponse()).Times(0);
EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_)).Times(0);
+ EXPECT_CALL(*cache_manager_, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_FALSE(policy_manager_->LoadPT(kFilePtUpdateJson, msg));
EXPECT_CALL(*cache_manager_, IsPTPreloaded());
EXPECT_FALSE(policy_manager_->GetCache()->IsPTPreloaded());
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 47b3959aee..ed7754e102 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
@@ -148,8 +148,9 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) {
std::shared_ptr<policy_table::Table> snapshot =
std::make_shared<policy_table::Table>(update.policy_table);
+ ON_CALL(*cache_manager_, GenerateSnapshot()).WillByDefault(Return(snapshot));
+
// Assert
- EXPECT_CALL(*cache_manager_, GenerateSnapshot()).WillOnce(Return(snapshot));
EXPECT_CALL(*cache_manager_, ApplyUpdate(_)).WillOnce(Return(true));
EXPECT_CALL(listener_, GetAppName("1234"))
.WillOnce(Return(custom_str::CustomString("")));
@@ -158,6 +159,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) {
EXPECT_CALL(*cache_manager_, TimeoutResponse());
EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_));
+ EXPECT_CALL(*cache_manager_, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_TRUE(policy_manager_->LoadPT(kFilePtUpdateJson, msg));
EXPECT_CALL(*cache_manager_, IsPTPreloaded());
EXPECT_FALSE(policy_manager_->GetCache()->IsPTPreloaded());
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 82d87cd7ba..90c213b75f 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
@@ -207,7 +207,7 @@ PolicyManagerImplTest::PolicyManagerImplTest()
void PolicyManagerImplTest::SetUp() {
policy_manager_ = new PolicyManagerImpl();
- cache_manager_ = new MockCacheManagerInterface();
+ cache_manager_ = new NiceMock<MockCacheManagerInterface>();
policy_manager_->set_cache_manager(cache_manager_);
policy_manager_->set_listener(&listener_);
@@ -260,7 +260,7 @@ void PolicyManagerImplTest2::SetUp() {
ON_CALL(policy_settings_, app_storage_folder())
.WillByDefault(ReturnRef(app_storage_folder_));
policy_manager_->set_listener(&listener_);
- const char* levels[] = {"BACKGROUND", "FULL", "LIMITED", "NONE"};
+ const char* levels[] = {"FULL", "LIMITED", "BACKGROUND", "NONE"};
hmi_level_.assign(levels, levels + sizeof(levels) / sizeof(levels[0]));
srand(time(NULL));
index_ = rand() % 3;
diff --git a/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc
index a9c7667ba6..7d40210ba4 100644
--- a/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc
+++ b/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc
@@ -1541,8 +1541,8 @@ TEST_F(SQLPTExtRepresentationTest, SaveFunctionalGroupings_ExpectedSaved) {
const HmiLevel test_level_1 = HL_FULL;
const HmiLevel test_level_2 = HL_LIMITED;
- const policy_table::Parameter test_parameter_1 = P_GPS;
- const policy_table::Parameter test_parameter_2 = P_SPEED;
+ const std::string test_parameter_1 = "P_GPS";
+ const std::string test_parameter_2 = "P_SPEED";
Rpcs rpcs;
@@ -1578,7 +1578,7 @@ TEST_F(SQLPTExtRepresentationTest, SaveFunctionalGroupings_ExpectedSaved) {
*another_rpcs.user_consent_prompt = another_user_consent_prompt;
const HmiLevel test_level_3 = HL_BACKGROUND;
- const policy_table::Parameter test_parameter_3 = P_BELTSTATUS;
+ const std::string test_parameter_3 = "P_BELTSTATUS";
RpcParameters another_parameters;
another_parameters.hmi_levels.push_back(test_level_3);
@@ -1615,10 +1615,10 @@ TEST_F(SQLPTExtRepresentationTest, SaveFunctionalGroupings_ExpectedSaved) {
EXPECT_TRUE(
(IsKeyExist<HmiLevels>(loaded_parameters.hmi_levels, test_level_2)));
- EXPECT_TRUE((
- IsKeyExist<Parameters>(*loaded_parameters.parameters, test_parameter_1)));
- EXPECT_TRUE((
- IsKeyExist<Parameters>(*loaded_parameters.parameters, test_parameter_2)));
+ EXPECT_TRUE((IsKeyExist<Parameters, std::string>(
+ *loaded_parameters.parameters, test_parameter_1)));
+ EXPECT_TRUE((IsKeyExist<Parameters, std::string>(
+ *loaded_parameters.parameters, test_parameter_2)));
Rpcs another_loaded_rpcs = GetKeyData<FunctionalGroupings, Rpcs>(
loaded_groupings, another_group_name);
@@ -1637,8 +1637,8 @@ TEST_F(SQLPTExtRepresentationTest, SaveFunctionalGroupings_ExpectedSaved) {
EXPECT_TRUE((IsKeyExist<HmiLevels>(another_loaded_parameters.hmi_levels,
test_level_3)));
- EXPECT_TRUE((IsKeyExist<Parameters>(*another_loaded_parameters.parameters,
- test_parameter_3)));
+ EXPECT_TRUE((IsKeyExist<Parameters, std::string>(
+ *another_loaded_parameters.parameters, test_parameter_3)));
}
TEST_F(SQLPTExtRepresentationTest, JsonContentsExternalConsent_ExpectParsed) {
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 dd75f54707..67702ab4d2 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
@@ -176,7 +176,7 @@ class SQLPTRepresentationTest : public SQLPTRepresentation,
policy_table::Strings& temp_groups = apps_iter->second.groups;
StringsCompare(groups, temp_groups);
EXPECT_EQ(0u, (*(apps_iter->second.nicknames)).size());
- EXPECT_EQ(prio, apps_iter->second.priority);
+ EXPECT_EQ(prio, (apps_iter->second).priority);
EXPECT_EQ(0u, (*(apps_iter->second.AppHMIType)).size());
EXPECT_EQ(memory_kb, (*(apps_iter->second.memory_kb)));
EXPECT_EQ(heart_beat_timeout_ms,
@@ -378,18 +378,23 @@ class SQLPTRepresentationTest2 : public ::testing::Test {
TEST_F(SQLPTRepresentationTest, VehicleDataItem_Store_Item) {
policy_table::VehicleDataItem rpm;
+ rpm.mark_initialized();
rpm.name = "rpm";
rpm.type = "Integer";
rpm.key = "OEM_REF_RPM";
rpm.mandatory = false;
*rpm.array = false;
- rpm.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
- ASSERT_FALSE(reps->VehicleDataItemExists(rpm.name, rpm.key));
+ rpm.params->mark_initialized();
+ ASSERT_FALSE(reps->VehicleDataItemExists(rpm));
ASSERT_TRUE(reps->InsertVehicleDataItem(rpm));
- ASSERT_TRUE(reps->VehicleDataItemExists(rpm.name, rpm.key));
+ ASSERT_TRUE(reps->VehicleDataItemExists(rpm));
auto rpm_retrieved = reps->GetVehicleDataItem(rpm.name, rpm.key);
- ASSERT_EQ(rpm.ToJsonValue(), rpm_retrieved.ToJsonValue());
+
+ std::cout << rpm.ToJsonValue().toStyledString() << std::endl;
+ std::cout << rpm_retrieved.ToJsonValue().toStyledString() << std::endl;
+
+ ASSERT_EQ(rpm.ToJsonValue(), rpm_retrieved.begin()->ToJsonValue());
}
TEST_F(SQLPTRepresentationTest, VehicleDataItem_Store_Complete_Item) {
@@ -399,7 +404,6 @@ TEST_F(SQLPTRepresentationTest, VehicleDataItem_Store_Complete_Item) {
message.key = "OEM_REF_MSG";
message.mandatory = false;
*message.array = false;
- message.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
*message.since = "1.0";
*message.until = "5.0";
*message.removed = false;
@@ -410,53 +414,59 @@ TEST_F(SQLPTRepresentationTest, VehicleDataItem_Store_Complete_Item) {
*message.maxsize = 255;
*message.minlength = 0;
*message.maxlength = 255;
+ message.params->mark_initialized();
ASSERT_TRUE(reps->InsertVehicleDataItem(message));
auto message_retrieved = reps->GetVehicleDataItem(message.name, message.key);
- ASSERT_EQ(message.ToJsonValue(), message_retrieved.ToJsonValue());
+ ASSERT_EQ(message.ToJsonValue(), message_retrieved.begin()->ToJsonValue());
}
TEST_F(SQLPTRepresentationTest, VehicleDataItem_Store_Struct) {
policy_table::VehicleDataItem alss;
+ alss.mark_initialized();
alss.name = "ambientLightSensorStatus";
alss.type = "AmbientLightStatus";
alss.key = "OEM_REF_AMB_LIGHT";
alss.mandatory = false;
- alss.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
+ alss.params->mark_initialized();
policy_table::VehicleDataItem lss;
+ lss.mark_initialized();
lss.name = "LightSensorStatus";
lss.type = "Struct";
lss.key = "OEM_REF_SEN_LIGHT";
lss.mandatory = false;
- lss.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
- lss.params.push_back(alss);
+ lss.params->mark_initialized();
+ (*lss.params).push_back(alss);
policy_table::VehicleDataItem hbo;
+ hbo.mark_initialized();
hbo.name = "highBeamsOn";
hbo.type = "Boolean";
hbo.key = "OEM_REF_HIGH_BEAM";
hbo.mandatory = true;
- hbo.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
+ hbo.params->mark_initialized();
policy_table::VehicleDataItem lbo;
+ lbo.mark_initialized();
lbo.name = "lowBeamsOn";
lbo.type = "Boolean";
lbo.key = "OEM_REF_LOW_BEAM";
lbo.mandatory = false;
- lbo.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
+ lbo.params->mark_initialized();
policy_table::VehicleDataItem hls;
+ hls.mark_initialized();
hls.name = "headLampStatus";
hls.type = "Struct";
hls.key = "OEM_REF_HLSTATUS";
hls.mandatory = false;
- hls.params = rpc::Array<policy_table::VehicleDataItem, 0, 255>();
- hls.params.push_back(lss);
- hls.params.push_back(lbo);
- hls.params.push_back(hbo);
+ hls.params->mark_initialized();
+ (*hls.params).push_back(lss);
+ (*hls.params).push_back(lbo);
+ (*hls.params).push_back(hbo);
ASSERT_TRUE(reps->InsertVehicleDataItem(alss));
ASSERT_TRUE(reps->InsertVehicleDataItem(hls));
auto hls_retrieved = reps->GetVehicleDataItem(hls.name, hls.key);
- ASSERT_EQ(hls.ToJsonValue(), hls_retrieved.ToJsonValue());
+ ASSERT_EQ(hls.ToJsonValue(), hls_retrieved.begin()->ToJsonValue());
}
TEST_F(SQLPTRepresentationTest2,
@@ -489,8 +499,8 @@ TEST_F(SQLPTRepresentationTest,
query.Prepare(query_select);
query.Next();
- // 37 - is current total tables number created by schema
- const int policy_tables_number = 37;
+ // 41 - is current total tables number created by schema
+ const int policy_tables_number = 41;
ASSERT_EQ(policy_tables_number, query.GetInteger(0));
const std::string query_select_count_of_iap_buffer_full =
@@ -1759,9 +1769,8 @@ TEST_F(SQLPTRepresentationTest,
const ::policy_table::Parameters& parameters = *(rpc_iter->second.parameters);
EXPECT_EQ(1u, parameters.size());
- EXPECT_TRUE(parameters.end() != std::find(parameters.begin(),
- parameters.end(),
- policy_table::Parameter::P_SPEED));
+ EXPECT_TRUE(parameters.end() !=
+ std::find(parameters.begin(), parameters.end(), "P_SPEED"));
// Check Application Policies Section
GatherApplicationPoliciesSection(&policies);
const uint32_t apps_size = 3u;
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 7c717c9756..5dab64e67d 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -725,10 +725,12 @@ const std::vector<policy_table::VehicleDataItem>
CacheManager::GetVehicleDataItems() const {
CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>());
sync_primitives::AutoLock auto_lock(cache_lock_);
- const auto vehicle_data_items =
- *(pt_->policy_table.vehicle_data->schema_items);
+ if (pt_->policy_table.vehicle_data.is_initialized() &&
+ pt_->policy_table.vehicle_data->schema_items.is_initialized()) {
+ return *(pt_->policy_table.vehicle_data->schema_items);
+ }
- return vehicle_data_items;
+ return std::vector<policy_table::VehicleDataItem>();
}
Json::Value CacheManager::GetPolicyTableData() const {
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 42361b2569..5a02e823e8 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -166,7 +166,7 @@ void FilterInvalidFunctions(policy_table::Rpc& rpcs) {
*/
void FilterInvalidRPCParameters(
policy_table::RpcParameters& rpc_parameters,
- policy_table::VehicleDataItems& vehicle_data_items) {
+ const std::vector<policy_table::VehicleDataItem>& vehicle_data_items) {
policy_table::HmiLevels valid_hmi_levels;
for (const auto& hmi_level : rpc_parameters.hmi_levels) {
if (hmi_level.is_valid()) {
@@ -182,7 +182,9 @@ void FilterInvalidRPCParameters(
return true;
}
- if (!vehicle_data_items.is_initialized()) {
+ // In case when this collection is empty that means collection is not
+ // initialized
+ if (vehicle_data_items.empty()) {
return false;
}
@@ -282,8 +284,9 @@ void FilterInvalidApplicationParameters(
* @brief FilterPolicyTable filter values that not present in schema
* @param pt policy table to filter
*/
-void FilterPolicyTable(policy_table::PolicyTable& pt,
- policy_table::VehicleDataItems& current_vd_items) {
+void FilterPolicyTable(
+ policy_table::PolicyTable& pt,
+ const std::vector<policy_table::VehicleDataItem>& current_vd_items) {
policy_table::ModuleConfig& module_config = pt.module_config;
if (module_config.is_initialized() &&
module_config.notifications_per_minute_by_priority.is_initialized()) {
@@ -357,11 +360,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
return false;
}
- const auto& current_vd = cache_->pt()->policy_table.vehicle_data;
- auto current_vd_items =
- current_vd.is_initialized() && current_vd->schema_items.is_initialized()
- ? *(current_vd->schema_items)
- : policy_table::VehicleDataItems();
+ auto current_vd_items = GetVehicleDataItems();
FilterPolicyTable(pt_update->policy_table, current_vd_items);
if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
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 9444bb4bcc..99e558af8a 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
@@ -799,9 +799,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) {
std::make_shared<policy_table::Table>(update.policy_table);
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
EXPECT_CALL(listener, GetAppName("1234"))
.WillOnce(Return(custom_str::CustomString("")));
@@ -833,9 +832,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_FunctionalGroup_removeRPC_SendUpdate) {
::policy::BinaryMessage msg(json.begin(), json.end());
// Assert
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
ExpectOnPermissionsUpdated();
@@ -869,9 +867,8 @@ TEST_F(PolicyManagerImplTest,
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
ExpectOnPermissionsUpdated();
@@ -904,9 +901,8 @@ TEST_F(PolicyManagerImplTest,
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
ExpectOnPermissionsUpdated();
@@ -940,9 +936,8 @@ TEST_F(PolicyManagerImplTest,
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
ExpectOnPermissionsUpdated();
@@ -975,9 +970,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_FunctionalGroup_addRPCParams_SendUpdate) {
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
ExpectOnPermissionsUpdated();
@@ -1003,9 +997,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_FunctionalGroup_NoUpdate_DONT_SendUpdate) {
// Assert
EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot));
- EXPECT_CALL(*cache_manager, pt()).WillOnce(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ EXPECT_CALL(*cache_manager, GetVehicleDataItems())
+ .WillOnce(Return(std::vector<policy_table::VehicleDataItem>()));
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true));
EXPECT_TRUE(manager->LoadPT("file_pt_update.json", msg));
@@ -1030,9 +1023,8 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetInvalidUpdatePT_PTIsNotLoaded) {
std::shared_ptr<policy_table::Table> snapshot =
std::make_shared<policy_table::Table>(update.policy_table);
ON_CALL(*cache_manager, GenerateSnapshot()).WillByDefault(Return(snapshot));
- ON_CALL(*cache_manager, pt()).WillByDefault(Return(snapshot));
- snapshot->policy_table.vehicle_data->schema_items =
- rpc::Optional<policy_table::VehicleDataItems>();
+ ON_CALL(*cache_manager, GetVehicleDataItems())
+ .WillByDefault(Return(std::vector<policy_table::VehicleDataItem>()));
// Assert
EXPECT_CALL(*cache_manager, ApplyUpdate(_)).Times(0);