diff options
author | JackLivio <jack@livio.io> | 2018-10-19 15:05:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 15:05:09 -0400 |
commit | d36316738785c96dab2ee892762ed08c059fffde (patch) | |
tree | 168a7c0705b5bc8f0dee7ce4b511ccf71759d9b4 /src/components/policy/policy_external/src/cache_manager.cc | |
parent | 7f7fcbb998fb17f2954fd103349af67ea9b71a3f (diff) | |
parent | 83c5e805346d55ec7fb9f4ba8b6f6855d992273e (diff) | |
download | sdl_core-d36316738785c96dab2ee892762ed08c059fffde.tar.gz |
Merge pull request #2572 from smartdevicelink/release/5.0.05.0.0hotfix/templates_updatesfeature/show_app_menufeature/progress_bar_seekfeature/open-menu-rpcfeature/open-menu-rfeature/button
Release 5.0.0
Diffstat (limited to 'src/components/policy/policy_external/src/cache_manager.cc')
-rw-r--r-- | src/components/policy/policy_external/src/cache_manager.cc | 145 |
1 files changed, 120 insertions, 25 deletions
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 5aa39cb2f4..c2c2e91257 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -41,6 +41,7 @@ #include <vector> #include "utils/file_system.h" +#include "utils/helpers.h" #include "json/reader.h" #include "json/features.h" #include "json/writer.h" @@ -206,6 +207,21 @@ struct ExternalConsentConsentGroupAppender } }; +struct DefaultPolicyUpdater { + DefaultPolicyUpdater(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_; +}; + } // namespace namespace policy { @@ -252,8 +268,7 @@ CacheManager::CacheManager() : CacheManagerInterface() , pt_(new policy_table::Table) , backup_(new SQLPTExtRepresentation()) - , update_required(false) - , cache_lock_(true) { + , update_required(false) { InitBackupThread(); } @@ -261,8 +276,7 @@ CacheManager::CacheManager(bool in_memory) : CacheManagerInterface() , pt_(new policy_table::Table) , backup_(new SQLPTExtRepresentation(in_memory)) - , update_required(false) - , cache_lock_(true) { + , update_required(false) { InitBackupThread(); } @@ -638,13 +652,11 @@ void CacheManager::RemoveAppConsentForGroup(const std::string& app_id, } } -using rpc::policy_table_interface_base::RequestTypes; -using rpc::policy_table_interface_base::RequestType; - void CacheManager::ProcessUpdate( const policy_table::ApplicationPolicies::const_iterator initial_policy_iter) { using namespace policy; + using rpc::policy_table_interface_base::RequestTypes; const RequestTypes& new_request_types = *(initial_policy_iter->second.RequestType); @@ -684,6 +696,13 @@ void CacheManager::ProcessUpdate( initial_policy_iter->second; *(pt_->policy_table.app_policies_section.apps[app_id].RequestType) = merged_pt_request_types; + + if (app_id == kDefaultId) { + std::for_each(pt_->policy_table.app_policies_section.apps.begin(), + pt_->policy_table.app_policies_section.apps.end(), + DefaultPolicyUpdater( + pt_->policy_table.app_policies_section.apps[app_id])); + } } bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { @@ -1120,8 +1139,8 @@ bool CacheManager::SetUserPermissionsForApp( it_group->second != is_allowed) { *out_app_permissions_changed = true; - const TimevalStruct tm = date_time::DateTime::getCurrentTime(); - int64_t current_time_msec = date_time::DateTime::getmSecs(tm); + const date_time::TimeDuration tm = date_time::getCurrentTime(); + int64_t current_time_msec = date_time::getmSecs(tm); ucr.consent_last_updated = current_time_msec; LOG4CXX_DEBUG(logger_, "Updating consents time " << current_time_msec); } @@ -1334,7 +1353,7 @@ 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; + date_time::MILLISECONDS_IN_SECOND; } bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) { @@ -1520,6 +1539,9 @@ void CacheManager::CheckSnapshotInitialization() { *(snapshot_->policy_table.module_config.preloaded_pt) = false; + *(snapshot_->policy_table.module_config.full_app_id_supported) = + settings_->use_full_app_id(); + // SDL must not send certificate in snapshot snapshot_->policy_table.module_config.certificate = rpc::Optional<rpc::String<0, 65535> >(); @@ -1628,8 +1650,8 @@ void CacheManager::CheckSnapshotInitialization() { void CacheManager::PersistData() { LOG4CXX_AUTO_TRACE(logger_); - if (backup_.valid()) { - if (pt_.valid()) { + if (backup_.use_count() != 0) { + if (pt_.use_count() != 0) { // Comma expression is used to hold the lock only during the constructor // call policy_table::Table copy_pt( @@ -1671,7 +1693,7 @@ void CacheManager::PersistData() { } // In case of extended policy the meta info should be backuped as well. - if (ex_backup_.valid()) { + if (ex_backup_.use_count() != 0) { ex_backup_->SetMetaInfo( *(*copy_pt.policy_table.module_meta).ccpu_version, *(*copy_pt.policy_table.module_meta).wers_country_code, @@ -1751,9 +1773,9 @@ bool CacheManager::IsPermissionsCalculated(const std::string& device_id, return false; } -utils::SharedPtr<policy_table::Table> CacheManager::GenerateSnapshot() { +std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() { CACHE_MANAGER_CHECK(snapshot_); - snapshot_ = new policy_table::Table(); + snapshot_ = std::make_shared<policy_table::Table>(); sync_primitives::AutoLock auto_lock(cache_lock_); snapshot_->policy_table = pt_->policy_table; @@ -2238,8 +2260,7 @@ bool CacheManager::Init(const std::string& file_name, LOG4CXX_AUTO_TRACE(logger_); settings_ = settings; InitResult init_result = backup_->Init(settings); - ex_backup_ = utils::SharedPtr<PTRepresentation>::dynamic_pointer_cast< - PTExtRepresentation>(backup_); + ex_backup_ = std::dynamic_pointer_cast<PTExtRepresentation>(backup_); bool result = true; switch (init_result) { @@ -2262,7 +2283,7 @@ bool CacheManager::Init(const std::string& file_name, case InitResult::SUCCESS: { LOG4CXX_INFO(logger_, "Policy Table was inited successfully"); result = LoadFromFile(file_name, *pt_); - utils::SharedPtr<policy_table::Table> snapshot = GenerateSnapshot(); + std::shared_ptr<policy_table::Table> snapshot = GenerateSnapshot(); result &= snapshot->is_valid(); LOG4CXX_DEBUG(logger_, @@ -2392,6 +2413,32 @@ bool CacheManager::ResetPT(const std::string& file_name) { return result; } +policy::RequestType::State CacheManager::GetAppRequestTypesState( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock auto_lock(cache_lock_); + policy_table::ApplicationPolicies::const_iterator app_policies_iter = + pt_->policy_table.app_policies_section.apps.find(policy_app_id); + if (pt_->policy_table.app_policies_section.apps.end() == app_policies_iter) { + LOG4CXX_DEBUG(logger_, + "Can't find request types for app_id " << policy_app_id); + return policy::RequestType::State::UNAVAILABLE; + } + const policy_table::RequestTypes& request_types = + *app_policies_iter->second.RequestType; + if (!request_types.is_initialized()) { + LOG4CXX_TRACE(logger_, + "Request types for " << policy_app_id << " are OMITTED"); + return RequestType::State::OMITTED; + } + if (request_types.empty()) { + LOG4CXX_TRACE(logger_, + "Request types for " << policy_app_id << " are EMPTY"); + return policy::RequestType::State::EMPTY; + } + return policy::RequestType::State::AVAILABLE; +} + void CacheManager::GetAppRequestTypes( const std::string& policy_app_id, std::vector<std::string>& request_types) const { @@ -2411,16 +2458,64 @@ void CacheManager::GetAppRequestTypes( return; } if (policy_iter->second.RequestType.is_initialized()) { - policy_table::RequestTypes::iterator it_request_type = - policy_iter->second.RequestType->begin(); - for (; it_request_type != policy_iter->second.RequestType->end(); - ++it_request_type) { - request_types.push_back(EnumToJsonString(*it_request_type)); + for (const auto& request_type : *policy_iter->second.RequestType) { + request_types.push_back(EnumToJsonString(request_type)); } } return; } +RequestSubType::State CacheManager::GetAppRequestSubTypesState( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock auto_lock(cache_lock_); + policy_table::ApplicationPolicies::const_iterator app_policies_iter = + pt_->policy_table.app_policies_section.apps.find(policy_app_id); + if (pt_->policy_table.app_policies_section.apps.end() == app_policies_iter) { + LOG4CXX_DEBUG(logger_, + "Can't find request subtypes for app_id " << policy_app_id); + return RequestSubType::State::UNAVAILABLE; + } + const policy_table::RequestSubTypes& request_subtypes = + *app_policies_iter->second.RequestSubType; + if (!request_subtypes.is_initialized()) { + LOG4CXX_TRACE(logger_, + "Request subtypes for " << policy_app_id << " are OMITTED"); + return RequestSubType::State::OMITTED; + } + if (request_subtypes.empty()) { + LOG4CXX_TRACE(logger_, + "Request subtypes for " << policy_app_id << " are EMPTY"); + return RequestSubType::State::EMPTY; + } + return RequestSubType::State::AVAILABLE; +} + +void CacheManager::GetAppRequestSubTypes( + const std::string& policy_app_id, + std::vector<std::string>& request_subtypes) const { + LOG4CXX_AUTO_TRACE(logger_); + CACHE_MANAGER_CHECK_VOID(); + if (kDeviceId == policy_app_id) { + LOG4CXX_DEBUG(logger_, + "Request subtypes not applicable for app_id " << kDeviceId); + return; + } + sync_primitives::AutoLock auto_lock(cache_lock_); + policy_table::ApplicationPolicies::iterator policy_iter = + pt_->policy_table.app_policies_section.apps.find(policy_app_id); + if (pt_->policy_table.app_policies_section.apps.end() == policy_iter) { + LOG4CXX_DEBUG(logger_, + "Can't find request subtypes for app_id " << policy_app_id); + return; + } + + for (const auto& request_subtype : *policy_iter->second.RequestSubType) { + request_subtypes.push_back(request_subtype); + } + return; +} + const MetaInfo CacheManager::GetMetaInfo() const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(cache_lock_); @@ -2578,8 +2673,8 @@ void CacheManager::SetExternalConsentForApp( (*(*pt_->policy_table.device_data)[permissions.device_id] .user_consent_records)[permissions.policy_app_id]; - const TimevalStruct tm = date_time::DateTime::getCurrentTime(); - int64_t current_time_msec = date_time::DateTime::getmSecs(tm); + const date_time::TimeDuration tm = date_time::getCurrentTime(); + int64_t current_time_msec = date_time::getmSecs(tm); app_consent_records.ext_consent_last_updated = current_time_msec; LOG4CXX_DEBUG(logger_, "Updating consents time " << current_time_msec); |