Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix applying heart_beat_timeout_ms from PreDataConsent #1551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
21 changes: 21 additions & 0 deletions src/components/application_manager/src/policies/policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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_,
Expand Down
16 changes: 16 additions & 0 deletions src/components/policy/policy_external/src/cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -674,13 +677,22 @@ 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);

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
Expand Down Expand Up @@ -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 =
Copy link
Collaborator

@iCollin iCollin Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I misunderstanding that we just set the entry to a string, not an object?

Is this not what the policy entry would look like?
pt_->policy_table.app_policies_section.apps[app_id]:

"app_policies": {
  "app_id": "pre_DataConsent"
}

It was my understanding we don't need to set properties on app_policies.app_id as it is a reference to app_policies.pre_DataConsent where the correct heartbeat timeout ms should live.

i see that this change does fix the issue, but really, when an app's section (app_policies_section.apps[app_id]) is a reference (like "app_id": "pre_DataConsent") should the properties like heart_beat_timeout_ms be pulled from the app that the reference points to (in provided case, that would be app_policies_section.apps["pre_DataConsent"])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iCollin in this example we just mark that entry as a reference to preData entity and assign value of preData.heart_beat_timeout_ms to app_id.heart_beat_timeout_ms, however preData is still the initial source of that value. Looks like there was no another place where SDL pulls that value from preData.
When snapshot is generated, this app_id will be properly collapsed into record you mentioned above.

pt_->policy_table.app_policies_section.apps[kPreDataConsentId]
.heart_beat_timeout_ms;
}

return true;
Expand Down