summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVeronica Veremjova (GitHub) <ninvica@gmail.com>2020-12-22 16:47:24 +0200
committerGitHub <noreply@github.com>2020-12-22 09:47:24 -0500
commit218aee15ea7d37dbca773e09cb391d0d229886d6 (patch)
tree007a52b3c2892d1e3b560fed06c8435ed5ea6f4a
parent8a4bf49140b02b7150e12f6f92e02720efeebfee (diff)
downloadsdl_core-218aee15ea7d37dbca773e09cb391d0d229886d6.tar.gz
Fix applying heart_beat_timeout_ms from PreDataConsent (#1551)
* Fix applying heart_beat_timeout_ms from PreDataConsent After sending SDL.OnAllowSDLFunctionality(allowed = false) application is assigned to PreDataConsent group. After this HB timeout is set to timeout from PreDataConsent * Updated logs messages and simplify vars after review * Update unit tests * Fix syntax errors after rebase * fixup! Fix syntax errors after rebase Co-authored-by: Veronica Veremjova <vveremjova@luxoft.com> Co-authored-by: Andrii Kalinich <AKalinich@luxoft.com>
-rw-r--r--src/components/application_manager/include/application_manager/policies/policy_handler.h3
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc21
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc6
-rw-r--r--src/components/policy/policy_external/src/cache_manager.cc16
4 files changed, 43 insertions, 3 deletions
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 c123bcc764..61b228d4f8 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<application_manager::ApplicationSharedPtr> Applications;
/**
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index b61a75d7de..cb9b7df3e1 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<PolicyManager> 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 39ad034d6f..a66cff1727 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 1b5f668e9a..783a622b2e 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;