diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index c123bcc764f..61b228d4f89 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -812,6 +812,9 @@ class PolicyHandler : public PolicyHandlerInterface, */ void LinkAppsToDevice(); + void SetHeartBeatTimeout(const std::string& policy_app_id, + const uint32_t app_id); + typedef std::vector Applications; /** diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index b61a75d7def..cb9b7df3e1b 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -600,6 +600,10 @@ void PolicyHandler::OnDeviceConsentChanged(const std::string& device_id, policy_manager->SendNotificationOnPermissionsUpdated(device_id, policy_app_id); + + if (policy_manager->IsPredataPolicy(policy_app_id) && !is_allowed) { + SetHeartBeatTimeout(policy_app_id, (*it_app_list)->app_id()); + } } } } @@ -767,6 +771,23 @@ void PolicyHandler::OnAppPermissionConsentInternal( #endif } +void PolicyHandler::SetHeartBeatTimeout(const std::string& policy_app_id, + const uint32_t app_id) { + SDL_LOG_AUTO_TRACE(); + + const std::shared_ptr policy_manager = LoadPolicyManager(); + POLICY_LIB_CHECK_VOID(policy_manager); + + const uint32_t timeout = policy_manager->HeartBeatTimeout(policy_app_id); + if (0 != timeout) { + SDL_LOG_DEBUG("SetHeartBeatTimeout for " << app_id << " is " << timeout); + application_manager_.connection_handler().SetHeartBeatTimeout(app_id, + timeout); + } else { + SDL_LOG_DEBUG("SetHeartBeatTimeout for " << app_id << " ignored"); + } +} + void policy::PolicyHandler::SetDaysAfterEpoch() { const auto policy_manager = LoadPolicyManager(); POLICY_LIB_CHECK_VOID(policy_manager); diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 39ad034d6f6..a66cff17270 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -1915,7 +1915,7 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentAllowed) { EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) - .WillOnce(Return(true)); + .WillRepeatedly(Return(true)); EXPECT_CALL( *mock_policy_manager_, @@ -1944,7 +1944,7 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentNotAllowed) { EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) - .WillOnce(Return(true)); + .WillRepeatedly(Return(true)); EXPECT_CALL(*mock_policy_manager_, ReactOnUserDevConsentForApp(handle, kPolicyAppId_, is_allowed)) @@ -1976,7 +1976,7 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_PredatePolicyNotAllowed) { // App does not have predate policy EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) - .WillOnce(Return(false)); + .WillRepeatedly(Return(false)); EXPECT_CALL( *mock_policy_manager_, diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 1b5f668e9a2..783a622b2ec 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -356,10 +356,12 @@ bool CacheManager::CanAppKeepContext(const std::string& app_id) const { } uint32_t CacheManager::HeartBeatTimeout(const std::string& app_id) const { + SDL_LOG_AUTO_TRACE(); CACHE_MANAGER_CHECK(0); sync_primitives::AutoLock auto_lock(cache_lock_); uint32_t result = 0; if (!IsApplicationRepresented(app_id)) { + SDL_LOG_WARN("Application " << app_id << " is not represented"); return result; } @@ -369,6 +371,7 @@ uint32_t CacheManager::HeartBeatTimeout(const std::string& app_id) const { result = *(app.heart_beat_timeout_ms); } + SDL_LOG_DEBUG("HB timer for app " << app_id << " is " << result); return result; } @@ -674,6 +677,7 @@ void CacheManager::ProcessUpdate( const policy_table::ApplicationPolicies::const_iterator initial_policy_iter) { using namespace policy; + using rpc::policy_table_interface_base::ApplicationParams; using rpc::policy_table_interface_base::RequestTypes; const RequestTypes& new_request_types = *(initial_policy_iter->second.RequestType); @@ -681,6 +685,14 @@ void CacheManager::ProcessUpdate( const std::string& app_id = initial_policy_iter->first; bool update_request_types = true; + ApplicationParams& params = + pt_->policy_table.app_policies_section.apps[app_id]; + if (kPreDataConsentId == app_id) { + *(params.heart_beat_timeout_ms) = + *(initial_policy_iter->second.heart_beat_timeout_ms); + SDL_LOG_INFO("heart_beat_timeout_ms in predata = " + << *(params.heart_beat_timeout_ms)); + } if (app_id == kDefaultId || app_id == kPreDataConsentId) { if (new_request_types.is_omitted()) { SDL_LOG_INFO("Application " << app_id @@ -2528,6 +2540,10 @@ bool policy::CacheManager::SetIsPredata(const std::string& app_id) { if (IsApplicationRepresented(app_id)) { pt_->policy_table.app_policies_section.apps[app_id].set_to_string( kPreDataConsentId); + + pt_->policy_table.app_policies_section.apps[app_id].heart_beat_timeout_ms = + pt_->policy_table.app_policies_section.apps[kPreDataConsentId] + .heart_beat_timeout_ms; } return true;