diff options
author | atimchenko <atymchenko@luxoft.com> | 2017-04-21 16:52:10 +0300 |
---|---|---|
committer | okozlovlux <okozlov@luxoft.com> | 2017-05-17 19:27:11 +0300 |
commit | 9cb25e928fc2591554e997e1ed8d5f4eb553dbc7 (patch) | |
tree | b346de1172968532f2d20bc5f2721b12b113beb4 /src/components/policy | |
parent | 0e55be0a471b55429bed079f684a8aa2a391c5c8 (diff) | |
download | sdl_core-9cb25e928fc2591554e997e1ed8d5f4eb553dbc7.tar.gz |
Fix SDL ignores externalConsentStatus
Fixed SDL ignores externalConsentStatus when is sent together with consentedFunction in OnAppPermissionConsent notification.
Fixed policy handler unit tests
Fixed policy_manager_implementation unit tests
Diffstat (limited to 'src/components/policy')
10 files changed, 125 insertions, 35 deletions
diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index 1d01cd86ca..fca750e11c 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -631,6 +631,7 @@ class CacheManager : public CacheManagerInterface { bool SetExternalConsentStatus(const ExternalConsentStatus& status) OVERRIDE; ExternalConsentStatus GetExternalConsentStatus() OVERRIDE; + ExternalConsentStatus GetExternalConsentEntities() OVERRIDE; /** * @brief Creates collection of ExternalConsent items known by current diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index 877b8fe50e..ebb224212e 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -714,7 +714,12 @@ class CacheManagerInterface { * @return external consent status */ virtual ExternalConsentStatus GetExternalConsentStatus() = 0; - + /** + * @brief Creates externalConsentStatus data structure from policy table + section "externalConsentStatus" + * @return ExternalConsentStatus data structure + */ + virtual ExternalConsentStatus GetExternalConsentEntities() = 0; /** * @brief Creates collection of ExternalConsent items known by current * functional diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index e84b57c366..d5bf26b84d 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -111,7 +111,8 @@ class PolicyManagerImpl : public PolicyManager { virtual void SetDeviceInfo(const std::string& device_id, const DeviceInfo& device_info); - virtual void SetUserConsentForApp(const PermissionConsent& permissions); + void SetUserConsentForApp(const PermissionConsent& permissions, + const NotificationMode mode) OVERRIDE; virtual bool GetDefaultHmi(const std::string& policy_app_id, std::string* default_hmi) const; @@ -216,6 +217,15 @@ class PolicyManagerImpl : public PolicyManager { const EndpointUrls& urls) const OVERRIDE; /** + * @brief Checks, if SDL needs to update it's policy table section + "external_consent_status" + * @param ExternalConsent status + * @return true if such check is needed, false - if not. + */ + bool IsNeedToUpdateExternalConsentStatus( + const ExternalConsentStatus& status) const; + + /** * @brief Gets customer connectivity settings status * @return ExternalConsent status */ diff --git a/src/components/policy/policy_external/include/policy/policy_types.h b/src/components/policy/policy_external/include/policy/policy_types.h index 7360fac726..00eab0cac1 100644 --- a/src/components/policy/policy_external/include/policy/policy_types.h +++ b/src/components/policy/policy_external/include/policy/policy_types.h @@ -401,6 +401,15 @@ struct ExternalConsentStatusItem { const EntityStatus status) : entity_type_(type), entity_id_(id), status_(status) {} + ExternalConsentStatusItem() {} + + ExternalConsentStatusItem operator=(const ExternalConsentStatusItem& rhs) { + this->entity_id_ = rhs.entity_id_; + this->entity_type_ = rhs.entity_type_; + this->status_ = rhs.status_; + return *this; // calls copy constructor + } + bool operator==(const ExternalConsentStatusItem& rhs) const { return (entity_type_ == rhs.entity_type_) && (entity_id_ == rhs.entity_id_); } @@ -409,9 +418,9 @@ struct ExternalConsentStatusItem { return (entity_type_ < rhs.entity_type_) || (entity_id_ < rhs.entity_id_); } - const uint32_t entity_type_; - const uint32_t entity_id_; - const EntityStatus status_; + uint32_t entity_type_; + uint32_t entity_id_; + EntityStatus status_; }; struct ExternalConsentStatusItemSorter { diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index e3b14668a8..764f0172b6 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1020,7 +1020,6 @@ bool CacheManager::SetUserPermissionsForApp( permissions.group_permissions.begin(); std::vector<FunctionalGroupPermission>::const_iterator iter_end = permissions.group_permissions.end(); - if (out_app_permissions_changed) { *out_app_permissions_changed = false; } @@ -1035,20 +1034,16 @@ bool CacheManager::SetUserPermissionsForApp( GetGroupNameByHashID((*iter).group_id, group_name); - const bool set_group_to_allowed = - (policy::kGroupAllowed == (*iter).state); - if (out_app_permissions_changed) { - policy_table::ConsentGroups::const_iterator found_consent_group_it = - ucr.consent_groups->find(group_name); - // Permission change occurs if there is no group that has ever been - // consented or consent status of the existing one differs from the - // requested - *out_app_permissions_changed = - (ucr.consent_groups->end() == found_consent_group_it || - set_group_to_allowed != found_consent_group_it->second); + policy_table::ConsentGroups::const_iterator it_group = + ucr.consent_groups->find(group_name); + + const bool is_allowed = (*iter).state == policy::kGroupAllowed; + if (ucr.consent_groups->end() == it_group || + it_group->second != is_allowed) { + *out_app_permissions_changed = true; } - (*ucr.consent_groups)[group_name] = set_group_to_allowed; + (*ucr.consent_groups)[group_name] = is_allowed; *ucr.input = policy_table::Input::I_GUI; *ucr.time_stamp = currentDateTime(); } @@ -2015,14 +2010,12 @@ long CacheManager::ConvertSecondsToMinute(int seconds) { bool CacheManager::SetDefaultPolicy(const std::string& app_id) { CACHE_MANAGER_CHECK(false); sync_primitives::AutoLock lock(cache_lock_); - policy_table::ApplicationPolicies::const_iterator iter = - pt_->policy_table.app_policies_section.apps.find(kDefaultId); - if (pt_->policy_table.app_policies_section.apps.end() != iter) { - pt_->policy_table.app_policies_section.apps[app_id] = - pt_->policy_table.app_policies_section.apps[kDefaultId]; + auto& apps = pt_->policy_table.app_policies_section.apps; - SetIsDefault(app_id); - } + DCHECK_OR_RETURN(IsApplicationRepresented(kDefaultId), false); + + apps[app_id] = apps[kDefaultId]; + apps[app_id].set_to_string(kDefaultId); Backup(); return true; } @@ -2350,6 +2343,35 @@ GroupsByExternalConsentStatus CacheManager::GetGroupsWithSameEntities( return groups_by_external_consent; } +ExternalConsentStatus CacheManager::GetExternalConsentEntities() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock auto_lock(cache_lock_); + ExternalConsentStatus items; + for (policy_table::FunctionalGroupings::const_iterator it = + pt_->policy_table.functional_groupings.begin(); + it != pt_->policy_table.functional_groupings.end(); + ++it) { + policy_table::DisallowedByExternalConsentEntities::const_iterator it_1 = + (*it->second.disallowed_by_external_consent_entities_on).begin(); + for (; + it_1 != (*it->second.disallowed_by_external_consent_entities_on).end(); + ++it_1) { + items.insert(ExternalConsentStatusItem( + it_1->entity_type, it_1->entity_id, EntityStatus::kStatusOn)); + } + policy_table::DisallowedByExternalConsentEntities::const_iterator it_2 = + (*it->second.disallowed_by_external_consent_entities_off).begin(); + for (; it_2 != + (*it->second.disallowed_by_external_consent_entities_off).end(); + ++it_2) { + items.insert(ExternalConsentStatusItem( + it_2->entity_type, it_2->entity_id, EntityStatus::kStatusOff)); + } + } + return items; +} + + std::map<std::string, std::string> CacheManager::GetKnownLinksFromPT() { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK((std::map<std::string, std::string>())); diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index a350a5d12a..de6b44236e 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -929,7 +929,7 @@ void PolicyManagerImpl::NotifyPermissionsChanges( } void PolicyManagerImpl::SetUserConsentForApp( - const PermissionConsent& permissions) { + const PermissionConsent& permissions, const NotificationMode mode) { LOG4CXX_AUTO_TRACE(logger_); if (permissions.group_permissions.empty()) { @@ -948,10 +948,16 @@ void PolicyManagerImpl::SetUserConsentForApp( return; } + if (kSilentMode == mode) { + LOG4CXX_WARN(logger_, + "Silent mode is enabled. Application won't be informed."); + return; + } + if (!app_permissions_changed) { LOG4CXX_WARN(logger_, - "Application permissions were not changed, skipping " - "permission change notification"); + "Application already has same consents. " + "Notificaton won't be sent."); return; } @@ -1247,7 +1253,8 @@ void PolicyManagerImpl::UpdateAppConsentWithExternalConsent( // Need to check to which app to send notification since maybe app registered // from different device - SetUserConsentForApp(updated_user_permissions); + SetUserConsentForApp(updated_user_permissions, + PolicyManager::kNotifyApplicationMode); PermissionConsent updated_external_consent_permissions; updated_external_consent_permissions.group_permissions = @@ -1323,6 +1330,37 @@ void PolicyManagerImpl::ProcessExternalConsentStatusUpdate( } } +bool ConsentStatusComparatorFunc(const ExternalConsentStatusItem& i1, + const ExternalConsentStatusItem& i2) { + return (i1.entity_id_ < i2.entity_id_) || + (i1.entity_type_ < i2.entity_type_) || (i1.status_ < i2.status_); +} + +bool PolicyManagerImpl::IsNeedToUpdateExternalConsentStatus( + const ExternalConsentStatus& new_status) const { + LOG4CXX_AUTO_TRACE(logger_); + typedef std::vector<ExternalConsentStatusItem> ItemV; + const ExternalConsentStatus existing_status = + cache_->GetExternalConsentEntities(); + + ItemV new_status_v(new_status.begin(), new_status.end()); + ItemV existing_status_v(existing_status.begin(), existing_status.end()); + + ItemV difference_v; + difference_v.resize(new_status_v.size() + existing_status_v.size()); + + ItemV::iterator ci = difference_v.begin(); + ci = std::set_difference(new_status_v.begin(), + new_status_v.end(), + existing_status_v.begin(), + existing_status_v.end(), + difference_v.begin(), + ConsentStatusComparatorFunc); + difference_v.resize(ci - difference_v.begin()); + + return !difference_v.empty(); +} + bool PolicyManagerImpl::SetExternalConsentStatus( const ExternalConsentStatus& status) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h b/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h index 93583822ae..bbe4a54db3 100644 --- a/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h +++ b/src/components/policy/policy_external/test/include/policy/mock_cache_manager.h @@ -239,6 +239,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD1(SetExternalConsentStatus, bool(const ExternalConsentStatus&)); MOCK_METHOD0(GetExternalConsentStatus, ExternalConsentStatus()); + MOCK_METHOD0(GetExternalConsentEntities, ExternalConsentStatus()); MOCK_METHOD1(GetGroupsWithSameEntities, GroupsByExternalConsentStatus(const ExternalConsentStatus&)); MOCK_METHOD0(GetKnownLinksFromPT, std::map<std::string, std::string>()); diff --git a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc index 8b40b70d41..c958f6bcd7 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc @@ -1044,7 +1044,8 @@ TEST_F(PolicyManagerImplTest2, groups_permissions.push_back(group1_perm); perm_consent.group_permissions = groups_permissions; - policy_manager_->SetUserConsentForApp(perm_consent); + policy_manager_->SetUserConsentForApp(perm_consent, + policy::PolicyManager::kSilentMode); policy_manager_->SendNotificationOnPermissionsUpdated(app_id_2_); std::vector< ::policy::FunctionalGroupPermission> actual_groups_permissions; std::vector< ::policy::FunctionalGroupPermission>::iterator it; @@ -1151,7 +1152,8 @@ TEST_F( groups_permissions.push_back(group1_perm); perm_consent.group_permissions = groups_permissions; - policy_manager_->SetUserConsentForApp(perm_consent); + policy_manager_->SetUserConsentForApp(perm_consent, + policy::PolicyManager::kSilentMode); policy_manager_->SendNotificationOnPermissionsUpdated(app_id_2_); std::vector< ::policy::FunctionalGroupPermission> actual_groups_permissions; std::vector< ::policy::FunctionalGroupPermission>::iterator it; @@ -1281,7 +1283,8 @@ TEST_F(PolicyManagerImplTest2, groups_permissions.push_back(group1_perm); perm_consent.group_permissions = groups_permissions; - policy_manager_->SetUserConsentForApp(perm_consent); + policy_manager_->SetUserConsentForApp(perm_consent, + policy::PolicyManager::kSilentMode); policy_manager_->SendNotificationOnPermissionsUpdated(app_id_2_); std::vector< ::policy::FunctionalGroupPermission> actual_groups_permissions; std::vector< ::policy::FunctionalGroupPermission>::iterator it; diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_test.cc index 3890bcb9e7..47f289a9e9 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_test.cc @@ -807,7 +807,7 @@ TEST_F(PolicyManagerImplTest_ExternalConsent, EXPECT_TRUE(policy_manager_->SetExternalConsentStatus(status)); - EXPECT_CALL(listener_, OnPermissionsUpdated(app_id_1_, _)).Times(0); + EXPECT_CALL(listener_, OnPermissionsUpdated(app_id_1_, _)); EXPECT_CALL(listener_, OnCurrentDeviceIdUpdateRequired(app_id_1_)) .WillRepeatedly(Return(device_id_1_)); @@ -932,7 +932,7 @@ TEST_F(PolicyManagerImplTest_ExternalConsent, EXPECT_TRUE(policy_manager_->SetExternalConsentStatus(status)); - EXPECT_CALL(listener_, OnPermissionsUpdated(app_id_1_, _)).Times(0); + EXPECT_CALL(listener_, OnPermissionsUpdated(app_id_1_, _)); EXPECT_CALL(listener_, OnCurrentDeviceIdUpdateRequired(app_id_1_)) .WillRepeatedly(Return(device_id_1_)); diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc index 82d958d2d1..ce34ca4400 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc @@ -794,7 +794,8 @@ void PolicyManagerImplTest_ExternalConsent:: permissions.group_permissions.push_back(group_permissions_1); permissions.group_permissions.push_back(group_permissions_2); - policy_manager_->SetUserConsentForApp(permissions); + policy_manager_->SetUserConsentForApp(permissions, + policy::PolicyManager::kSilentMode); } void PolicyManagerImplTest_ExternalConsent:: |