diff options
Diffstat (limited to 'src/components/policy/policy_external/src/cache_manager.cc')
-rw-r--r-- | src/components/policy/policy_external/src/cache_manager.cc | 123 |
1 files changed, 98 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..e4a4151fa4 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" @@ -252,8 +253,7 @@ CacheManager::CacheManager() : CacheManagerInterface() , pt_(new policy_table::Table) , backup_(new SQLPTExtRepresentation()) - , update_required(false) - , cache_lock_(true) { + , update_required(false) { InitBackupThread(); } @@ -261,8 +261,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 +637,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); @@ -1120,8 +1117,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 +1331,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 +1517,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 +1628,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 +1671,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 +1751,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 +2238,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 +2261,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 +2391,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 +2436,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 +2651,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); |