diff options
Diffstat (limited to 'src/components/policy/policy_regular/src')
7 files changed, 287 insertions, 56 deletions
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 377278949b..6a142374d5 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -83,11 +83,27 @@ struct LanguageFinder { const std::string& language_; }; +struct PolicyTableUpdater { + PolicyTableUpdater(const policy_table::ApplicationParams& default_params) + : default_params_(default_params) {} + + void operator()(policy_table::ApplicationPolicies::value_type& pt_value) { + if (policy::kDefaultId == pt_value.second.get_string()) { + pt_value.second = default_params_; + pt_value.second.set_to_string(policy::kDefaultId); + } + } + + private: + const policy_table::ApplicationParams& default_params_; +}; + CacheManager::CacheManager() : CacheManagerInterface() , pt_(new policy_table::Table) , backup_(new SQLPTRepresentation()) - , update_required(false) { + , update_required(false) + , cache_lock_(true) { LOG4CXX_AUTO_TRACE(logger_); backuper_ = new BackgroundBackuper(this); backup_thread_ = threads::CreateThread("Backup thread", backuper_); @@ -103,6 +119,7 @@ CacheManager::~CacheManager() { } const policy_table::Strings& CacheManager::GetGroups(const PTString& app_id) { + sync_primitives::AutoLock auto_lock(cache_lock_); return pt_->policy_table.app_policies_section.apps[app_id].groups; } @@ -114,6 +131,7 @@ bool CacheManager::CanAppKeepContext(const std::string& app_id) const { uint32_t CacheManager::HeartBeatTimeout(const std::string& app_id) const { CACHE_MANAGER_CHECK(0); + sync_primitives::AutoLock auto_lock(cache_lock_); uint32_t result = 0; if (!AppExists(app_id)) { return result; @@ -130,6 +148,7 @@ uint32_t CacheManager::HeartBeatTimeout(const std::string& app_id) const { const policy_table::AppHMITypes* CacheManager::GetHMITypes( const std::string& app_id) { + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& apps = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator i = apps.find(app_id); @@ -180,6 +199,7 @@ void CacheManager::GetAllAppGroups(const std::string& app_id, return; } + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator app_params_iter = pt_->policy_table.app_policies_section.apps.find(app_id); @@ -244,6 +264,11 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { ""); } else { pt_->policy_table.app_policies_section.apps[iter->first] = iter->second; + if (kDefaultId == iter->first) { + std::for_each(pt_->policy_table.app_policies_section.apps.begin(), + pt_->policy_table.app_policies_section.apps.end(), + PolicyTableUpdater(iter->second)); + } } } @@ -265,6 +290,7 @@ void CacheManager::GetHMIAppTypeAfterUpdate( std::map<std::string, StringArray>& app_hmi_types) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator policy_iter_begin = pt_->policy_table.app_policies_section.apps.begin(); policy_table::ApplicationPolicies::const_iterator policy_iter_end = @@ -288,6 +314,7 @@ void CacheManager::GetHMIAppTypeAfterUpdate( bool CacheManager::AppHasHMIType(const std::string& application_id, policy_table::AppHMIType hmi_type) const { + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; @@ -399,6 +426,7 @@ bool CacheManager::ReactOnUserDevConsentForApp(const std::string& app_id, void CacheManager::GetGroupNameByHashID(const int32_t group_id, std::string& group_name) { CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::FunctionalGroupings::const_iterator fg_iter = pt_->policy_table.functional_groupings.begin(); policy_table::FunctionalGroupings::const_iterator fg_iter_end = @@ -432,6 +460,7 @@ void CacheManager::SaveUpdateRequired(bool status) { bool CacheManager::IsApplicationRevoked(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); bool is_revoked = false; if (pt_->policy_table.app_policies_section.apps.end() != pt_->policy_table.app_policies_section.apps.find(app_id)) { @@ -447,6 +476,7 @@ void CacheManager::CheckPermissions(const policy_table::Strings& groups, CheckPermissionResult& result) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::Strings::const_iterator app_groups_iter = groups.begin(); policy_table::Strings::const_iterator app_groups_iter_end = groups.end(); @@ -463,6 +493,13 @@ void CacheManager::CheckPermissions(const policy_table::Strings& groups, if (rpcs.rpcs.end() != rpc_iter) { policy_table::RpcParameters rpc_param = rpc_iter->second; + if (rpc_param.parameters.is_initialized() && + rpc_param.parameters->empty()) { + // If "parameters" field exist in PT section of incoming RPC but empty + // all params considered as DISALLOWED + result.hmi_level_permitted = kRpcDisallowed; + return; + } policy_table::HmiLevel hmi_level_e; policy_table::EnumFromJsonString(hmi_level, &hmi_level_e); @@ -491,11 +528,13 @@ void CacheManager::CheckPermissions(const policy_table::Strings& groups, bool CacheManager::IsPTPreloaded() { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); return *pt_->policy_table.module_config.preloaded_pt; } int CacheManager::IgnitionCyclesBeforeExchange() { CACHE_MANAGER_CHECK(0); + sync_primitives::AutoLock auto_lock(cache_lock_); const uint8_t limit = std::max( static_cast<int>( pt_->policy_table.module_config.exchange_after_x_ignition_cycles), @@ -515,6 +554,7 @@ int CacheManager::IgnitionCyclesBeforeExchange() { int CacheManager::KilometersBeforeExchange(int current) { CACHE_MANAGER_CHECK(0); + sync_primitives::AutoLock auto_lock(cache_lock_); const int limit = std::max(static_cast<int>( pt_->policy_table.module_config.exchange_after_x_kilometers), @@ -535,6 +575,7 @@ int CacheManager::KilometersBeforeExchange(int current) { bool CacheManager::SetCountersPassedForSuccessfulUpdate( policy::Counters counter, int value) { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); switch (counter) { case KILOMETERS: *pt_->policy_table.module_meta->pt_exchanged_at_odometer_x = value; @@ -560,6 +601,7 @@ bool CacheManager::SetCountersPassedForSuccessfulUpdate( int CacheManager::DaysBeforeExchange(int current) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(0); + sync_primitives::AutoLock auto_lock(cache_lock_); const rpc::Optional<rpc::Integer<uint16_t, 0, 65535> >& days_after_epoch = (pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch); @@ -583,6 +625,7 @@ int CacheManager::DaysBeforeExchange(int current) { void CacheManager::IncrementIgnitionCycles() { CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); const int ign_val = static_cast<int>( *pt_->policy_table.module_meta->ignition_cycles_since_last_exchange); (*pt_->policy_table.module_meta->ignition_cycles_since_last_exchange) = @@ -593,18 +636,21 @@ void CacheManager::IncrementIgnitionCycles() { void CacheManager::ResetIgnitionCycles() { CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); (*pt_->policy_table.module_meta->ignition_cycles_since_last_exchange) = 0; Backup(); } int CacheManager::TimeoutResponse() { CACHE_MANAGER_CHECK(0); + sync_primitives::AutoLock auto_lock(cache_lock_); return pt_->policy_table.module_config.timeout_after_x_seconds * date_time::DateTime::MILLISECONDS_IN_SECOND; } bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); rpc::policy_table_interface_base::SecondsBetweenRetries::iterator iter = pt_->policy_table.module_config.seconds_between_retries.begin(); rpc::policy_table_interface_base::SecondsBetweenRetries::iterator iter_end = @@ -621,6 +667,7 @@ bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) { const policy::VehicleInfo CacheManager::GetVehicleInfo() const { CACHE_MANAGER_CHECK(VehicleInfo()); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ModuleConfig& module_config = pt_->policy_table.module_config; VehicleInfo vehicle_info; vehicle_info.vehicle_make = *module_config.vehicle_make; @@ -642,6 +689,7 @@ std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg( std::vector<std::string>::const_iterator it = msg_codes.begin(); std::vector<std::string>::const_iterator it_end = msg_codes.end(); + sync_primitives::AutoLock auto_lock(cache_lock_); for (; it != it_end; ++it) { policy_table::MessageLanguages msg_languages = (*pt_->policy_table.consumer_friendly_messages->messages)[*it]; @@ -701,6 +749,7 @@ void CacheManager::GetUpdateUrls(const std::string& service_type, LOG4CXX_DEBUG(logger_, "Search service value is: " << service_type); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ServiceEndpoints::const_iterator iter = pt_->policy_table.module_config.endpoints.find(service_type); @@ -733,6 +782,7 @@ CacheManager::GetNotificationsNumber(const std::string& priority) { CACHE_MANAGER_CHECK(0); typedef rpc::policy_table_interface_base::NumberOfNotificationsPerMinute NNPM; + sync_primitives::AutoLock auto_lock(cache_lock_); const NNPM& nnpm = pt_->policy_table.module_config.notifications_per_minute_by_priority; @@ -746,6 +796,7 @@ CacheManager::GetNotificationsNumber(const std::string& priority) { bool CacheManager::GetPriority(const std::string& policy_app_id, std::string& priority) const { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); if (kDeviceId == policy_app_id) { priority = EnumToJsonString( pt_->policy_table.app_policies_section.device.priority); @@ -884,9 +935,10 @@ void CacheManager::PersistData() { LOG4CXX_AUTO_TRACE(logger_); if (backup_.valid()) { if (pt_.valid()) { - cache_lock_.Acquire(); - policy_table::Table copy_pt(*pt_); - cache_lock_.Release(); + // Comma expression is used to hold the lock only during the constructor + // call + policy_table::Table copy_pt( + (sync_primitives::AutoLock(cache_lock_), *pt_)); backup_->Save(copy_pt); backup_->SaveUpdateRequired(update_required); @@ -978,12 +1030,12 @@ bool CacheManager::IsPermissionsCalculated(const std::string& device_id, utils::SharedPtr<policy_table::Table> CacheManager::GenerateSnapshot() { CACHE_MANAGER_CHECK(snapshot_); - sync_primitives::AutoLock lock(cache_lock_); snapshot_ = new policy_table::Table(); // Copy all members of policy table except messages in consumer friendly // messages + sync_primitives::AutoLock auto_lock(cache_lock_); snapshot_->policy_table.app_policies_section = pt_->policy_table.app_policies_section; snapshot_->policy_table.functional_groupings = @@ -1010,6 +1062,7 @@ bool CacheManager::GetInitialAppData(const std::string& app_id, StringArray& app_hmi_types) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator policy_iter = pt_->policy_table.app_policies_section.apps.find(app_id); @@ -1032,6 +1085,7 @@ bool CacheManager::GetFunctionalGroupings( policy_table::FunctionalGroupings& groups) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); const policy_table::FunctionalGroupings& f_groupings = pt_->policy_table.functional_groupings; @@ -1052,6 +1106,7 @@ bool CacheManager::SetMetaInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); // We have to set preloaded flag as false in policy table on any response // of GetSystemInfo (SDLAQ-CRS-2365) @@ -1076,6 +1131,7 @@ bool CacheManager::SetSystemLanguage(const std::string& language) { bool CacheManager::GetFunctionalGroupNames(FunctionalGroupNames& names) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); rpc::policy_table_interface_base::FunctionalGroupings::iterator iter = pt_->policy_table.functional_groupings.begin(); rpc::policy_table_interface_base::FunctionalGroupings::iterator iter_end = @@ -1209,7 +1265,7 @@ long CacheManager::ConvertSecondsToMinute(int seconds) { bool CacheManager::SetDefaultPolicy(const std::string& app_id) { CACHE_MANAGER_CHECK(false); - sync_primitives::AutoLock lock(cache_lock_); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator iter = pt_->policy_table.app_policies_section.apps.find(kDefaultId); if (pt_->policy_table.app_policies_section.apps.end() != iter) { @@ -1224,6 +1280,7 @@ bool CacheManager::SetDefaultPolicy(const std::string& app_id) { bool CacheManager::IsDefaultPolicy(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); const bool result = pt_->policy_table.app_policies_section.apps.end() != pt_->policy_table.app_policies_section.apps.find(app_id) && @@ -1235,6 +1292,7 @@ bool CacheManager::IsDefaultPolicy(const std::string& app_id) const { bool CacheManager::SetIsDefault(const std::string& app_id) { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator iter = pt_->policy_table.app_policies_section.apps.find(app_id); if (pt_->policy_table.app_policies_section.apps.end() != iter) { @@ -1246,7 +1304,7 @@ bool CacheManager::SetIsDefault(const std::string& app_id) { bool CacheManager::SetPredataPolicy(const std::string& app_id) { CACHE_MANAGER_CHECK(false); - sync_primitives::AutoLock lock(cache_lock_); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator iter = pt_->policy_table.app_policies_section.apps.find(kPreDataConsentId); @@ -1270,6 +1328,7 @@ bool CacheManager::SetPredataPolicy(const std::string& app_id) { bool CacheManager::IsPredataPolicy(const std::string& app_id) const { // TODO(AOleynik): Maybe change for comparison with pre_DataConsent // permissions or check string value from get_string() + sync_primitives::AutoLock auto_lock(cache_lock_); if (!IsApplicationRepresented(app_id)) { return false; } @@ -1296,6 +1355,7 @@ bool CacheManager::IsPredataPolicy(const std::string& app_id) const { bool CacheManager::SetUnpairedDevice(const std::string& device_id, bool unpaired) { + sync_primitives::AutoLock auto_lock(cache_lock_); const bool result = pt_->policy_table.device_data->end() != pt_->policy_table.device_data->find(device_id); if (!result) { @@ -1328,6 +1388,7 @@ bool CacheManager::IsApplicationRepresented(const std::string& app_id) const { if (kDeviceId == app_id) { return true; } + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::const_iterator iter = pt_->policy_table.app_policies_section.apps.find(app_id); return pt_->policy_table.app_policies_section.apps.end() != iter; @@ -1398,6 +1459,27 @@ bool CacheManager::LoadFromBackup() { return true; } +void CacheManager::MakeLowerCaseAppNames(policy_table::Table& pt) const { + policy_table::ApplicationPolicies& apps = + pt.policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::iterator iter = apps.begin(); + iter != apps.end();) { + std::string key = iter->first; + if (key == kDefaultId || key == kPreDataConsentId || key == kDeviceId) { + ++iter; + continue; + } + + std::transform(key.begin(), key.end(), key.begin(), ::tolower); + if (key.compare(iter->first) != 0) { + std::swap(apps[key], iter->second); + iter = apps.erase(iter); + } else { + ++iter; + } + } +} + bool CacheManager::LoadFromFile(const std::string& file_name, policy_table::Table& table) { LOG4CXX_AUTO_TRACE(logger_); @@ -1426,6 +1508,8 @@ bool CacheManager::LoadFromFile(const std::string& file_name, LOG4CXX_DEBUG(logger_, "PT out:"); LOG4CXX_DEBUG(logger_, s_writer.write(table.ToJsonValue())); + MakeLowerCaseAppNames(table); + if (!table.is_valid()) { rpc::ValidationReport report("policy_table"); table.ReportErrors(&report); @@ -1433,6 +1517,7 @@ bool CacheManager::LoadFromFile(const std::string& file_name, "Parsed table is not valid " << rpc::PrettyFormat(report)); return false; } + return true; } @@ -1444,6 +1529,7 @@ bool CacheManager::ResetPT(const std::string& file_name) { bool CacheManager::AppExists(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); + sync_primitives::AutoLock auto_lock(cache_lock_); policy_table::ApplicationPolicies::iterator policy_iter = pt_->policy_table.app_policies_section.apps.find(app_id); return pt_->policy_table.app_policies_section.apps.end() != policy_iter; @@ -1469,6 +1555,7 @@ void CacheManager::GetAppRequestTypes( std::vector<std::string>& request_types) const { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); if (kDeviceId == policy_app_id) { LOG4CXX_DEBUG(logger_, "Request types not applicable for app_id " << kDeviceId); @@ -1492,6 +1579,7 @@ void CacheManager::GetAppRequestTypes( std::string CacheManager::GetCertificate() const { CACHE_MANAGER_CHECK(std::string("")); + sync_primitives::AutoLock auto_lock(cache_lock_); if (pt_->policy_table.module_config.certificate.is_initialized()) { return *pt_->policy_table.module_config.certificate; } @@ -1588,6 +1676,12 @@ const PolicySettings& CacheManager::get_settings() const { return *settings_; } +void CacheManager::OnDeviceSwitching(const std::string& device_id_from, + const std::string& device_id_to) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger_, "Implementation does not support user consents."); +} + CacheManager::BackgroundBackuper::BackgroundBackuper( CacheManager* cache_manager) : cache_manager_(cache_manager) @@ -1615,9 +1709,10 @@ void CacheManager::BackgroundBackuper::threadMain() { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(need_backup_lock_); while (!stop_flag_) { - need_backup_lock_.Release(); - InternalBackup(); - need_backup_lock_.Acquire(); + { + sync_primitives::AutoUnlock unlock(need_backup_lock_); + InternalBackup(); + } if (new_data_available_ || stop_flag_) { continue; } diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc index b72a041a83..95f275769c 100644 --- a/src/components/policy/policy_regular/src/policy_helper.cc +++ b/src/components/policy/policy_regular/src/policy_helper.cc @@ -267,9 +267,7 @@ void policy::CheckAppPolicy::NotifySystem( } void CheckAppPolicy::SendPermissionsToApp( - const AppPoliciesValueType& app_policy) const { - const std::string app_id = app_policy.first; - + const std::string& app_id, const policy_table::Strings& groups) const { const std::string device_id = pm_->GetCurrentDeviceId(app_id); if (device_id.empty()) { LOG4CXX_WARN(logger_, @@ -281,7 +279,7 @@ void CheckAppPolicy::SendPermissionsToApp( Permissions notification_data; pm_->PrepareNotificationData(update_->policy_table.functional_groupings, - app_policy.second.groups, + groups, group_permissons, notification_data); @@ -356,6 +354,20 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { "Permissions for application:" << app_id << " have been changed."); + if (IsPredefinedApp(app_policy)) { + for (const policy_table::ApplicationPolicies::value_type& app : + snapshot_->policy_table.app_policies_section.apps) { + if (app_policy.first == app.second.get_string()) { + if (RESULT_CONSENT_NOT_REQIURED != result) { + SetPendingPermissions(app, result); + NotifySystem(app); + } + SendPermissionsToApp(app.first, app_policy.second.groups); + } + } + return true; + } + if (!IsPredefinedApp(app_policy) && RESULT_CONSENT_NOT_REQIURED != result) { SetPendingPermissions(app_policy, result); NotifySystem(app_policy); @@ -363,7 +375,7 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { // Don't sent notification for predefined apps (e.g. default, device etc.) if (!IsPredefinedApp(app_policy)) { - SendPermissionsToApp(app_policy); + SendPermissionsToApp(app_policy.first, app_policy.second.groups); } return true; } @@ -697,7 +709,7 @@ void FillFunctionalGroupPermissions( FunctionalGroupNames& names, GroupConsent state, std::vector<FunctionalGroupPermission>& permissions) { - LOG4CXX_INFO(logger_, "FillFunctionalGroupPermissions"); + LOG4CXX_AUTO_TRACE(logger_); FunctionalGroupIDs::const_iterator it = ids.begin(); FunctionalGroupIDs::const_iterator it_end = ids.end(); for (; it != it_end; ++it) { @@ -717,7 +729,7 @@ bool IsPredefinedApp(const AppPoliciesValueType& app) { FunctionalGroupIDs ExcludeSame(const FunctionalGroupIDs& from, const FunctionalGroupIDs& what) { - LOG4CXX_INFO(logger_, "Exclude same groups"); + LOG4CXX_AUTO_TRACE(logger_); FunctionalGroupIDs from_copy(from); FunctionalGroupIDs what_copy(what); @@ -739,7 +751,7 @@ FunctionalGroupIDs ExcludeSame(const FunctionalGroupIDs& from, FunctionalGroupIDs Merge(const FunctionalGroupIDs& first, const FunctionalGroupIDs& second) { - LOG4CXX_INFO(logger_, "Merge groups"); + LOG4CXX_AUTO_TRACE(logger_); FunctionalGroupIDs first_copy(first); FunctionalGroupIDs second_copy(second); 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 640b9c1457..39b303cbb5 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -366,6 +366,12 @@ void PolicyManagerImpl::OnAppRegisteredOnMobile( SendNotificationOnPermissionsUpdated(application_id); } +void PolicyManagerImpl::OnDeviceSwitching(const std::string& device_id_from, + const std::string& device_id_to) { + LOG4CXX_AUTO_TRACE(logger_); + cache_->OnDeviceSwitching(device_id_from, device_id_to); +} + const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes( const std::string policy_app_id) const { std::vector<std::string> request_types; @@ -748,7 +754,7 @@ void PolicyManagerImpl::GetPermissionsForApp( std::string& PolicyManagerImpl::GetCurrentDeviceId( const std::string& policy_app_id) const { - LOG4CXX_INFO(logger_, "GetDeviceInfo"); + LOG4CXX_AUTO_TRACE(logger_); last_device_id_ = listener()->OnCurrentDeviceIdUpdateRequired(policy_app_id); return last_device_id_; } diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc index e0f77be989..34d12420d8 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -161,6 +161,8 @@ bool IsValidEnum(Parameter val) { return true; case P_ECALLINFO: return true; + case P_EMPTY: + return true; default: return false; } @@ -217,10 +219,13 @@ const char* EnumToJsonString(Parameter val) { return "emergencyEvent"; case P_ECALLINFO: return "eCallInfo"; + case P_EMPTY: + return "EMPTY"; default: return ""; } } + bool EnumFromJsonString(const std::string& literal, Parameter* result) { if ("gps" == literal) { *result = P_GPS; @@ -297,6 +302,9 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) { } else if ("eCallInfo" == literal) { *result = P_ECALLINFO; return true; + } else if ("EMPTY" == literal) { + *result = P_EMPTY; + return true; } else { return false; } diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 27a43c84ad..5f6f85f5dd 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -308,19 +308,24 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { // RpcParameters methods RpcParameters::RpcParameters() : CompositeType(kUninitialized) {} + RpcParameters::RpcParameters(const HmiLevels& hmi_levels) : CompositeType(kUninitialized), hmi_levels(hmi_levels) {} + RpcParameters::~RpcParameters() {} + RpcParameters::RpcParameters(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , hmi_levels(impl::ValueMember(value__, "hmi_levels")) , parameters(impl::ValueMember(value__, "parameters")) {} + Json::Value RpcParameters::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("hmi_levels", hmi_levels, &result__); impl::WriteJsonField("parameters", parameters, &result__); return result__; } + bool RpcParameters::is_valid() const { if (!hmi_levels.is_valid()) { return false; @@ -330,9 +335,11 @@ bool RpcParameters::is_valid() const { } return Validate(); } + bool RpcParameters::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool RpcParameters::struct_empty() const { if (hmi_levels.is_initialized()) { return false; @@ -343,6 +350,7 @@ bool RpcParameters::struct_empty() const { return true; } + void RpcParameters::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -363,18 +371,23 @@ void RpcParameters::SetPolicyTableType(PolicyTableType pt_type) { // Rpcs methods Rpcs::Rpcs() : CompositeType(kUninitialized) {} + Rpcs::Rpcs(const Rpc& rpcs) : CompositeType(kUninitialized), rpcs(rpcs) {} + Rpcs::~Rpcs() {} + Rpcs::Rpcs(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , user_consent_prompt(impl::ValueMember(value__, "user_consent_prompt")) , rpcs(impl::ValueMember(value__, "rpcs")) {} + Json::Value Rpcs::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("user_consent_prompt", user_consent_prompt, &result__); impl::WriteJsonField("rpcs", rpcs, &result__); return result__; } + bool Rpcs::is_valid() const { if (!user_consent_prompt.is_valid()) { return false; @@ -384,9 +397,11 @@ bool Rpcs::is_valid() const { } return Validate(); } + bool Rpcs::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool Rpcs::struct_empty() const { if (user_consent_prompt.is_initialized()) { return false; @@ -397,6 +412,7 @@ bool Rpcs::struct_empty() const { return true; } + void Rpcs::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -418,6 +434,7 @@ void Rpcs::SetPolicyTableType(PolicyTableType pt_type) { // ModuleConfig methods ModuleConfig::ModuleConfig() : CompositeType(kUninitialized) {} + ModuleConfig::ModuleConfig( uint8_t exchange_after_x_ignition_cycles, int64_t exchange_after_x_kilometers, @@ -435,7 +452,9 @@ ModuleConfig::ModuleConfig( , endpoints(endpoints) , notifications_per_minute_by_priority( notifications_per_minute_by_priority) {} + ModuleConfig::~ModuleConfig() {} + ModuleConfig::ModuleConfig(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , device_certificates(impl::ValueMember(value__, "device_certificates")) @@ -501,6 +520,7 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("preloaded_date", preloaded_date, &result__); return result__; } + bool ModuleConfig::is_valid() const { if (!preloaded_pt.is_valid()) { return false; @@ -543,9 +563,11 @@ bool ModuleConfig::is_valid() const { } return Validate(); } + bool ModuleConfig::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool ModuleConfig::struct_empty() const { if (preloaded_pt.is_initialized()) { return false; @@ -587,6 +609,7 @@ bool ModuleConfig::struct_empty() const { } return true; } + void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -670,7 +693,9 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { // MessageString methods MessageString::MessageString() : CompositeType(kUninitialized) {} + MessageString::~MessageString() {} + MessageString::MessageString(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , line1(impl::ValueMember(value__, "line1")) @@ -678,6 +703,7 @@ MessageString::MessageString(const Json::Value* value__) , tts(impl::ValueMember(value__, "tts")) , label(impl::ValueMember(value__, "label")) , textBody(impl::ValueMember(value__, "textBody")) {} + Json::Value MessageString::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("line1", line1, &result__); @@ -687,6 +713,7 @@ Json::Value MessageString::ToJsonValue() const { impl::WriteJsonField("textBody", textBody, &result__); return result__; } + bool MessageString::is_valid() const { if (struct_empty()) { return initialization_state__ == kInitialized && Validate(); @@ -708,9 +735,11 @@ bool MessageString::is_valid() const { } return Validate(); } + bool MessageString::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool MessageString::struct_empty() const { if (line1.is_initialized()) { return false; @@ -731,6 +760,7 @@ bool MessageString::struct_empty() const { } return true; } + void MessageString::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -765,17 +795,22 @@ void MessageString::SetPolicyTableType(PolicyTableType pt_type) { const std::string MessageLanguages::default_language_("en-us"); MessageLanguages::MessageLanguages() : CompositeType(kUninitialized) {} + MessageLanguages::MessageLanguages(const Languages& languages) : CompositeType(kUninitialized), languages(languages) {} + MessageLanguages::~MessageLanguages() {} + MessageLanguages::MessageLanguages(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , languages(impl::ValueMember(value__, "languages")) {} + Json::Value MessageLanguages::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("languages", languages, &result__); return result__; } + bool MessageLanguages::is_valid() const { if (!languages.is_valid()) { return false; @@ -786,9 +821,11 @@ bool MessageLanguages::is_valid() const { } return Validate(); } + bool MessageLanguages::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool MessageLanguages::struct_empty() const { if (languages.is_initialized()) { return false; @@ -827,19 +864,24 @@ void MessageLanguages::SetPolicyTableType(PolicyTableType pt_type) { // ConsumerFriendlyMessages methods ConsumerFriendlyMessages::ConsumerFriendlyMessages() : CompositeType(kUninitialized) {} + ConsumerFriendlyMessages::ConsumerFriendlyMessages(const std::string& version) : CompositeType(kUninitialized), version(version) {} + ConsumerFriendlyMessages::~ConsumerFriendlyMessages() {} + ConsumerFriendlyMessages::ConsumerFriendlyMessages(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , version(impl::ValueMember(value__, "version")) , messages(impl::ValueMember(value__, "messages")) {} + Json::Value ConsumerFriendlyMessages::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("version", version, &result__); impl::WriteJsonField("messages", messages, &result__); return result__; } + bool ConsumerFriendlyMessages::is_valid() const { if (!version.is_valid()) { return false; @@ -849,9 +891,11 @@ bool ConsumerFriendlyMessages::is_valid() const { } return Validate(); } + bool ConsumerFriendlyMessages::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool ConsumerFriendlyMessages::struct_empty() const { if (version.is_initialized()) { return false; @@ -862,6 +906,7 @@ bool ConsumerFriendlyMessages::struct_empty() const { return true; } + void ConsumerFriendlyMessages::ReportErrors( rpc::ValidationReport* report__) const { if (struct_empty()) { @@ -892,7 +937,9 @@ void ConsumerFriendlyMessages::SetPolicyTableType(PolicyTableType pt_type) { // ModuleMeta methods ModuleMeta::ModuleMeta() : CompositeType(kUninitialized) {} + ModuleMeta::~ModuleMeta() {} + ModuleMeta::ModuleMeta(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , pt_exchanged_at_odometer_x( @@ -901,6 +948,7 @@ ModuleMeta::ModuleMeta(const Json::Value* value__) impl::ValueMember(value__, "pt_exchanged_x_days_after_epoch")) , ignition_cycles_since_last_exchange( impl::ValueMember(value__, "ignition_cycles_since_last_exchange")) {} + Json::Value ModuleMeta::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField( @@ -913,6 +961,7 @@ Json::Value ModuleMeta::ToJsonValue() const { &result__); return result__; } + bool ModuleMeta::is_valid() const { if (struct_empty()) { return initialization_state__ == kInitialized && Validate(); @@ -928,9 +977,11 @@ bool ModuleMeta::is_valid() const { } return Validate(); } + bool ModuleMeta::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool ModuleMeta::struct_empty() const { if (pt_exchanged_at_odometer_x.is_initialized()) { return false; @@ -944,6 +995,7 @@ bool ModuleMeta::struct_empty() const { } return true; } + void ModuleMeta::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -1006,7 +1058,9 @@ AppLevel::AppLevel(uint16_t minutes_in_hmi_full, , count_of_tls_errors(count_of_tls_errors) , count_of_run_attempts_while_revoked(count_of_run_attempts_while_revoked) { } + AppLevel::~AppLevel() {} + AppLevel::AppLevel(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , minutes_in_hmi_full(impl::ValueMember(value__, "minutes_in_hmi_full")) @@ -1042,6 +1096,7 @@ Json::Value AppLevel::ToJsonValue() const { impl::WriteJsonField("count_of_TLS_errors", count_of_tls_errors, &result__); return result__; } + bool AppLevel::is_valid() const { if (!minutes_in_hmi_full.is_valid()) { return false; @@ -1090,9 +1145,11 @@ bool AppLevel::is_valid() const { } return Validate(); } + bool AppLevel::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool AppLevel::struct_empty() const { if (minutes_in_hmi_full.is_initialized()) { return false; @@ -1147,6 +1204,7 @@ bool AppLevel::struct_empty() const { } return true; } + void AppLevel::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -1171,6 +1229,7 @@ Json::Value UsageAndErrorCounts::ToJsonValue() const { impl::WriteJsonField("app_level", app_level, &result__); return result__; } + bool UsageAndErrorCounts::is_valid() const { if (struct_empty()) { return initialization_state__ == kInitialized && Validate(); @@ -1180,15 +1239,18 @@ bool UsageAndErrorCounts::is_valid() const { } return Validate(); } + bool UsageAndErrorCounts::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool UsageAndErrorCounts::struct_empty() const { if (app_level.is_initialized()) { return false; } return true; } + void UsageAndErrorCounts::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -1211,25 +1273,32 @@ void UsageAndErrorCounts::SetPolicyTableType(PolicyTableType pt_type) { // DeviceParams methods DeviceParams::DeviceParams() : CompositeType(kUninitialized) {} + DeviceParams::~DeviceParams() {} + DeviceParams::DeviceParams(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) {} + Json::Value DeviceParams::ToJsonValue() const { Json::Value result__(Json::objectValue); return result__; } + bool DeviceParams::is_valid() const { if (struct_empty()) { return initialization_state__ == kInitialized && Validate(); } return Validate(); } + bool DeviceParams::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool DeviceParams::struct_empty() const { return true; } + void DeviceParams::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -1238,6 +1307,7 @@ void DeviceParams::ReportErrors(rpc::ValidationReport* report__) const { // PolicyTable methods PolicyTable::PolicyTable() : CompositeType(kUninitialized) {} + PolicyTable::PolicyTable( const ApplicationPoliciesSection& app_policies_section, const FunctionalGroupings& functional_groupings, @@ -1248,7 +1318,9 @@ PolicyTable::PolicyTable( , functional_groupings(functional_groupings) , consumer_friendly_messages(consumer_friendly_messages) , module_config(module_config) {} + PolicyTable::~PolicyTable() {} + PolicyTable::PolicyTable(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , app_policies_section(impl::ValueMember(value__, "app_policies")) @@ -1260,6 +1332,7 @@ PolicyTable::PolicyTable(const Json::Value* value__) , usage_and_error_counts( impl::ValueMember(value__, "usage_and_error_counts")) , device_data(impl::ValueMember(value__, "device_data")) {} + Json::Value PolicyTable::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("app_policies", app_policies_section, &result__); @@ -1273,6 +1346,7 @@ Json::Value PolicyTable::ToJsonValue() const { impl::WriteJsonField("device_data", device_data, &result__); return result__; } + bool PolicyTable::is_valid() const { if (!app_policies_section.is_valid()) { return false; @@ -1297,9 +1371,11 @@ bool PolicyTable::is_valid() const { } return Validate(); } + bool PolicyTable::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool PolicyTable::struct_empty() const { if (app_policies_section.is_initialized()) { return false; @@ -1327,6 +1403,7 @@ bool PolicyTable::struct_empty() const { } return true; } + void PolicyTable::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); @@ -1381,32 +1458,40 @@ void PolicyTable::SetPolicyTableType(PolicyTableType pt_type) { // Table methods Table::Table() : CompositeType(kUninitialized) {} + Table::Table(const PolicyTable& policy_table) : CompositeType(kUninitialized), policy_table(policy_table) {} + Table::~Table() {} + Table::Table(const Json::Value* value__) : CompositeType(InitHelper(value__, &Json::Value::isObject)) , policy_table(impl::ValueMember(value__, "policy_table")) {} + Json::Value Table::ToJsonValue() const { Json::Value result__(Json::objectValue); impl::WriteJsonField("policy_table", policy_table, &result__); return result__; } + bool Table::is_valid() const { if (!policy_table.is_valid()) { return false; } return Validate(); } + bool Table::is_initialized() const { return (initialization_state__ != kUninitialized) || (!struct_empty()); } + bool Table::struct_empty() const { if (policy_table.is_initialized()) { return false; } return true; } + void Table::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index 7938eb4085..ef4ef49273 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -123,7 +123,7 @@ const std::string kCreateSchema = "CREATE INDEX `rpc.select_rpc_name_hmi_level` " " ON `rpc`(`name`,`hmi_level_value`);" "CREATE TABLE IF NOT EXISTS `application`( " - " `id` VARCHAR(45) PRIMARY KEY NOT NULL, " + " `id` VARCHAR(45) PRIMARY KEY NOT NULL COLLATE NOCASE, " " `keep_context` BOOLEAN, " " `steal_focus` BOOLEAN, " " `default_hmi` VARCHAR(45), " @@ -147,7 +147,7 @@ const std::string kCreateSchema = "CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` " " ON `application`(`priority_value`); " "CREATE TABLE IF NOT EXISTS `app_group`( " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " " PRIMARY KEY(`application_id`,`functional_group_id`), " " CONSTRAINT `fk_application_has_functional_group_application1` " @@ -162,9 +162,9 @@ const std::string kCreateSchema = " ON `app_group`(`functional_group_id`); " "CREATE INDEX IF NOT EXISTS " "`app_group.fk_application_has_functional_group_application1_idx` " - " ON `app_group`(`application_id`); " + " ON `app_group`(`application_id` COLLATE NOCASE); " "CREATE TABLE IF NOT EXISTS `preconsented_group`( " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " " PRIMARY KEY(`application_id`,`functional_group_id`), " " CONSTRAINT `fk_application_has_functional_group_application2` " @@ -180,7 +180,7 @@ const std::string kCreateSchema = " ON `preconsented_group`(`functional_group_id`); " "CREATE INDEX IF NOT EXISTS " "`preconsented_group.fk_application_has_functional_group_application2_idx` " - " ON `preconsented_group`(`application_id`); " + " ON `preconsented_group`(`application_id` COLLATE NOCASE); " "CREATE TABLE IF NOT EXISTS `seconds_between_retry`( " " `index` INTEGER PRIMARY KEY NOT NULL, " " `value` INTEGER NOT NULL " @@ -207,7 +207,7 @@ const std::string kCreateSchema = "`device_consent_group.fk_device_has_functional_group_device1_idx` " " ON `device_consent_group`(`device_id`); " "CREATE TABLE IF NOT EXISTS `app_level`( " - " `application_id` VARCHAR(45) PRIMARY KEY NOT NULL, " + " `application_id` VARCHAR(45) PRIMARY KEY NOT NULL COLLATE NOCASE, " " `minutes_in_hmi_full` INTEGER DEFAULT 0, " " `minutes_in_hmi_limited` INTEGER DEFAULT 0, " " `minutes_in_hmi_background` INTEGER DEFAULT 0, " @@ -234,24 +234,24 @@ const std::string kCreateSchema = " REFERENCES `language`(`code`) " "); " "CREATE INDEX IF NOT EXISTS `app_level.fk_app_levels_application1_idx` " - " ON `app_level`(`application_id`); " + " ON `app_level`(`application_id` COLLATE NOCASE); " "CREATE INDEX IF NOT EXISTS `app_level.fk_app_level_language1_idx` " " ON `app_level`(`app_registration_language_gui`); " "CREATE INDEX IF NOT EXISTS `app_level.fk_app_level_language2_idx` " " ON `app_level`(`app_registration_language_vui`); " "CREATE TABLE IF NOT EXISTS `nickname`( " - " `name` VARCHAR(100) NOT NULL, " - " `application_id` VARCHAR(45) NOT NULL, " + " `name` VARCHAR(100) NOT NULL COLLATE NOCASE, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " PRIMARY KEY(`name`,`application_id`), " " CONSTRAINT `fk_nickname_application1` " " FOREIGN KEY(`application_id`) " " REFERENCES `application`(`id`) " "); " "CREATE INDEX IF NOT EXISTS `nickname.fk_nickname_application1_idx` " - " ON `nickname`(`application_id`); " + " ON `nickname`(`application_id` COLLATE NOCASE); " "CREATE TABLE IF NOT EXISTS `app_type`( " " `name` VARCHAR(50) NOT NULL, " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " PRIMARY KEY(`name`,`application_id`), " " CONSTRAINT `fk_app_type_application1` " " FOREIGN KEY(`application_id`) " @@ -259,17 +259,17 @@ const std::string kCreateSchema = "); " "CREATE TABLE IF NOT EXISTS `request_type`( " " `request_type` VARCHAR(50) NOT NULL, " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " PRIMARY KEY(`request_type`,`application_id`), " " CONSTRAINT `fk_app_type_application1` " " FOREIGN KEY(`application_id`) " " REFERENCES `application`(`id`) " "); " "CREATE INDEX IF NOT EXISTS `app_type.fk_app_type_application1_idx` " - " ON `app_type`(`application_id`); " + " ON `app_type`(`application_id` COLLATE NOCASE); " "CREATE TABLE IF NOT EXISTS `consent_group`( " " `device_id` VARCHAR(100) NOT NULL, " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " " `is_consented` BOOL NOT NULL, " " `input` VARCHAR(45), " @@ -294,13 +294,13 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `endpoint`( " " `service` VARCHAR(100) NOT NULL, " " `url` VARCHAR(100) NOT NULL, " - " `application_id` VARCHAR(45) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " CONSTRAINT `fk_endpoint_application1` " " FOREIGN KEY(`application_id`) " " REFERENCES `application`(`id`) " "); " "CREATE INDEX IF NOT EXISTS `endpoint.fk_endpoint_application1_idx` " - " ON `endpoint`(`application_id`); " + " ON `endpoint`(`application_id` COLLATE NOCASE); " "CREATE TABLE IF NOT EXISTS `message`( " " `id` INTEGER PRIMARY KEY NOT NULL, " " `tts` TEXT, " diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index 04fc0d7658..9840a08b26 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -596,8 +596,8 @@ void SQLPTRepresentation::GatherDeviceData( bool SQLPTRepresentation::GatherFunctionalGroupings( policy_table::FunctionalGroupings* groups) const { LOG4CXX_INFO(logger_, "Gather Functional Groupings info"); - utils::dbms::SQLQuery func_group(db()); - if (!func_group.Prepare(sql_pt::kSelectFunctionalGroups)) { + utils::dbms::SQLQuery functional_group(db()); + if (!functional_group.Prepare(sql_pt::kSelectFunctionalGroups)) { LOG4CXX_WARN(logger_, "Incorrect select from functional_groupings"); return false; } @@ -606,32 +606,50 @@ bool SQLPTRepresentation::GatherFunctionalGroupings( LOG4CXX_WARN(logger_, "Incorrect select all from rpc"); return false; } - while (func_group.Next()) { - policy_table::Rpcs rpcs_tbl; - if (!func_group.IsNull(2)) { - *rpcs_tbl.user_consent_prompt = func_group.GetString(2); + + while (functional_group.Next()) { + policy_table::Rpcs rpcs_structure; + + if (!functional_group.IsNull(2)) { + *rpcs_structure.user_consent_prompt = functional_group.GetString(2); } - int func_id = func_group.GetInteger(0); - rpcs.Bind(0, func_id); + + const int group_id = functional_group.GetInteger(0); + + // Collecting RPCs with their HMI levels and parameters (if any) + rpcs.Bind(0, group_id); while (rpcs.Next()) { if (!rpcs.IsNull(1)) { policy_table::HmiLevel level; if (policy_table::EnumFromJsonString(rpcs.GetString(1), &level)) { - InsertUnique(level, &rpcs_tbl.rpcs[rpcs.GetString(0)].hmi_levels); + InsertUnique(level, + &rpcs_structure.rpcs[rpcs.GetString(0)].hmi_levels); } } if (!rpcs.IsNull(2)) { policy_table::Parameter param; - if (policy_table::EnumFromJsonString(rpcs.GetString(2), ¶m)) { - InsertUnique(param, &(*rpcs_tbl.rpcs[rpcs.GetString(0)].parameters)); + if (EnumFromJsonString(rpcs.GetString(2), ¶m)) { + // 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_structure.rpcs[rpcs.GetString(0)].parameters) + .mark_initialized(); + continue; + } + InsertUnique(param, + &(*rpcs_structure.rpcs[rpcs.GetString(0)].parameters)); } } } - if (!rpcs_tbl.rpcs.is_initialized()) { - rpcs_tbl.rpcs.set_to_null(); - } + rpcs.Reset(); - (*groups)[func_group.GetString(1)] = rpcs_tbl; + + if (!rpcs_structure.rpcs.is_initialized()) { + rpcs_structure.rpcs.set_to_null(); + } + policy_table::Rpcs& group_rpcs_structure = + (*groups)[functional_group.GetString(1)]; + group_rpcs_structure = rpcs_structure; } return true; } @@ -848,6 +866,18 @@ bool SQLPTRepresentation::SaveRpcs(int64_t group_id, return false; } } + } else if (parameters.is_initialized()) { + 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(policy_table::P_EMPTY))); + query_parameter.Bind(3, group_id); + if (!query_parameter.Exec() || !query_parameter.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into rpc with parameter"); + return false; + } } else { query.Bind(0, it->first); query.Bind(1, std::string(policy_table::EnumToJsonString(*hmi_it))); @@ -1834,12 +1864,7 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { return false; } - bool ret = (GatherAppGroup(kDefaultId, &default_groups) && - SaveAppGroup(app_id, default_groups)); - if (ret) { - return SetIsDefault(app_id, true); - } - return false; + return SetIsDefault(app_id, true); } bool SQLPTRepresentation::SetIsDefault(const std::string& app_id, |