diff options
Diffstat (limited to 'src/components/policy/policy_regular/src/policy_manager_impl.cc')
-rw-r--r-- | src/components/policy/policy_regular/src/policy_manager_impl.cc | 152 |
1 files changed, 148 insertions, 4 deletions
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 f4b6f0ae03..4985035629 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -143,6 +143,149 @@ void PolicyManagerImpl::CheckTriggers() { } } +/** + * @brief FilterInvalidFunctions filter functions that are absent in schema + * @param rpcs list of functions to filter + */ +void FilterInvalidFunctions(policy_table::Rpc& rpcs) { + policy_table::Rpc valid_rpcs; + for (const auto& rpc : rpcs) { + const std::string& rpc_name = rpc.first; + policy_table::FunctionID function_id; + if (policy_table::EnumFromJsonString(rpc_name, &function_id)) { + valid_rpcs.insert(rpc); + } + } + rpcs.swap(valid_rpcs); +} + +/** + * @brief FilterInvalidRPCParameters filter parameters that not present in + * schema + * @param rpc_parameters parameters to filter + */ +void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) { + policy_table::HmiLevels valid_hmi_levels; + for (const auto& hmi_level : rpc_parameters.hmi_levels) { + if (hmi_level.is_valid()) { + valid_hmi_levels.push_back(hmi_level); + } + } + rpc_parameters.hmi_levels.swap(valid_hmi_levels); + + policy_table::Parameters valid_params; + const policy_table::Parameters& params = *(rpc_parameters.parameters); + for (const auto& param : params) { + if (param.is_valid()) { + valid_params.push_back(param); + } + } + rpc_parameters.parameters->swap(valid_params); +} + +/** + * @brief FilterInvalidPriorityValues filter notification priorities that are + * not present in schema + * @param notifications priorities to filter + */ +void FilterInvalidPriorityValues( + policy_table::NumberOfNotificationsPerMinute& notifications) { + policy_table::NumberOfNotificationsPerMinute valid_notifications; + for (const auto& notification : notifications) { + policy_table::Priority priority; + if (policy_table::EnumFromJsonString(notification.first, &priority)) { + valid_notifications.insert(notification); + } + } + notifications.swap(valid_notifications); +} + +/** + * @brief FilterInvalidApplicationParameters filter app params that are not + * present in schema + * @param app_params object of app policy params to filter + */ +void FilterInvalidApplicationParameters( + policy_table::ApplicationParams& app_params) { + // Filter AppHMIType array + policy_table::AppHMITypes valid_app_hmi_types; + const policy_table::AppHMITypes& app_hmi_types = *(app_params.AppHMIType); + for (const auto& app_hmi_type : app_hmi_types) { + if (app_hmi_type.is_valid()) { + valid_app_hmi_types.push_back(app_hmi_type); + } + } + app_params.AppHMIType->swap(valid_app_hmi_types); + + // Filter RquestTypes array + policy_table::RequestTypes valid_request_types; + const policy_table::RequestTypes& request_types = *(app_params.RequestType); + for (const auto& request_type : request_types) { + if (request_type.is_valid()) { + valid_request_types.push_back(request_type); + } + } + if (valid_request_types.empty() && !request_types.empty()) { + // An empty RequestType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitialized value to + // for array to be "omitted" + *(app_params.RequestType) = policy_table::RequestTypes(); + } else { + app_params.RequestType->swap(valid_request_types); + } + + // Filter moduleType array + policy_table::ModuleTypes valid_module_types; + const policy_table::ModuleTypes& module_types = *(app_params.moduleType); + for (const auto& module_type : module_types) { + if (module_type.is_valid()) { + valid_module_types.push_back(module_type); + } + } + if (valid_module_types.empty() && !module_types.empty()) { + // An empty moduleType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitialized value to + // for array to be "omitted" + *(app_params.moduleType) = policy_table::ModuleTypes(); + } else { + app_params.moduleType->swap(valid_module_types); + } + + // Filter priority + if (!app_params.priority.is_valid()) { + app_params.priority = policy_table::Priority(); + } +} + +/** + * @brief FilterPolicyTable filter values that not present in schema + * @param pt policy table to filter + */ +void FilterPolicyTable(policy_table::PolicyTable& pt) { + policy_table::ModuleConfig& module_config = pt.module_config; + if (module_config.is_initialized() && + module_config.notifications_per_minute_by_priority.is_initialized()) { + FilterInvalidPriorityValues( + module_config.notifications_per_minute_by_priority); + } + + if (pt.app_policies_section.is_initialized()) { + policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps; + for (auto& app_policy : apps) { + FilterInvalidApplicationParameters(app_policy.second); + } + } + + for (auto& group : pt.functional_groupings) { + policy_table::Rpc& rpcs = group.second.rpcs; + FilterInvalidFunctions(rpcs); + + for (auto& func : rpcs) { + FilterInvalidRPCParameters(func.second); + } + } +} + bool PolicyManagerImpl::LoadPT(const std::string& file, const BinaryMessage& pt_content) { LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size()); @@ -168,6 +311,7 @@ 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(); @@ -1067,10 +1211,10 @@ StatusNotifier PolicyManagerImpl::AddApplication( AddNewApplication(application_id, device_consent); return std::make_shared<CallStatusChange>(update_status_manager_, device_consent); - } else { - PromoteExistedApplication(application_id, device_consent); - return std::make_shared<utils::CallNothing>(); } + PromoteExistedApplication(application_id, device_consent); + update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + return std::make_shared<utils::CallNothing>(); } void PolicyManagerImpl::RemoveAppConsentForGroup( @@ -1093,6 +1237,7 @@ void PolicyManagerImpl::AddNewApplication(const std::string& application_id, void PolicyManagerImpl::PromoteExistedApplication( const std::string& application_id, DeviceConsent device_consent) { + LOG4CXX_AUTO_TRACE(logger_); // If device consent changed to allowed during application being // disconnected, app permissions should be changed also if (kDeviceAllowed == device_consent && @@ -1145,7 +1290,6 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, const bool ret = cache_->Init(file_name, settings); if (ret) { RefreshRetrySequence(); - update_status_manager_.OnPolicyInit(cache_->UpdateRequired()); const std::string certificate_data = cache_->GetCertificate(); if (!certificate_data.empty()) { listener_->OnCertificateUpdated(certificate_data); |