diff options
author | Alexander Kutsan (GitHub) <akutsan@luxoft.com> | 2020-02-27 17:36:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-27 10:36:08 -0500 |
commit | f416c47429dd9a495c15ea6d078ea30ee2971b4a (patch) | |
tree | de72bb92b2c6ce2a89600b26555ea76a7a861052 /src/components/policy | |
parent | d5994e8111f2fe46d8735ef2680d4235dada807f (diff) | |
download | sdl_core-f416c47429dd9a495c15ea6d078ea30ee2971b4a.tar.gz |
Feature/Web Engine support (#3221)
* Add ini file parameters for WebEngineSupport
Issue : #3197
* Add Server WebSocket transport
* Policy changes for Web Engine support
Issue : #3197
* Changes in HMI_API for WebEngineSupport
Issue : #3197
* Add application manager implementation for WebEngineSupport
Add appropriate commands
Make changes in application manager
Issue : #3197
* Bug fix : Do not override message params if request setups it
* Update SDD
* fixup! Add application manager implementation for WebEngineSupport
* fixup! Add Server WebSocket transport
* Rename websocket dir to websocket_server
* Rename WebSocketTransport adapter to WebSocketServerTransportAdapter
* fixup! Update SDD
* Fix/update app list after unregistration (#3252)
* fixup! Rename WebSocketTransport adapter to WebSocketServerTransportAdapter
* fixup! Rename websocket dir to websocket_server
* Don't remove enabled WebEngine apps from pending apps
* Rework WebEngine device ID generation
* Fix build after back merge
* Fix get app properties (#3258)
Co-authored-by: Maksym Ked (GitHub) <41471947+mked-luxoft@users.noreply.github.com>
* Remove unused vin_code variable
Co-authored-by: Maksym Ked (GitHub) <41471947+mked-luxoft@users.noreply.github.com>
Co-authored-by: Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com>
Co-authored-by: Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com>
Co-authored-by: Andrii Kalinich (GitHub) <AKalinich@luxoft.com>
Diffstat (limited to 'src/components/policy')
19 files changed, 556 insertions, 249 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 5e3cf3dde7..b24e05fb6d 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -181,32 +181,18 @@ class CacheManager : public CacheManagerInterface { * @param enabled_apps List filled with the policy app id of each enabled * cloud application */ - virtual void GetEnabledCloudApps( - std::vector<std::string>& enabled_apps) const; + void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const OVERRIDE; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id + * of each enabled local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * Initializes a new cloud application with default policies 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 2cb5f8fe33..8e3f90b64f 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 @@ -190,29 +190,21 @@ class CacheManagerInterface { std::vector<std::string>& enabled_apps) const = 0; /** - * @brief Get cloud app policy information, all fields that aren't set for a + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + virtual std::vector<std::string> GetEnabledLocalApps() const = 0; + + /** + * @brief Get app policy information, all fields that aren't set for a * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const = 0; + * @param policy_app_id policy app id + * @param out_app_properties application properties + * @return true if application presents in database, otherwise - false + */ + virtual bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const = 0; /** * Initializes a new cloud application with default policies diff --git a/src/components/policy/policy_external/include/policy/policy_helper.h b/src/components/policy/policy_external/include/policy/policy_helper.h index 2054485ef5..69ba8806d4 100644 --- a/src/components/policy/policy_external/include/policy/policy_helper.h +++ b/src/components/policy/policy_external/include/policy/policy_helper.h @@ -231,6 +231,10 @@ struct CheckAppPolicy { void InsertPermission(const std::string& app_id, const AppPermissions& permissions_diff); + bool IsAppPropertiesChanged(const AppPoliciesValueType& app_policy) const; + + bool IsAppPropertiesProvided(const AppPoliciesValueType& app_policy) const; + private: PolicyManagerImpl* pm_; const std::shared_ptr<policy_table::Table> update_; 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 ce344d576a..57499131f9 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 @@ -667,28 +667,14 @@ class PolicyManagerImpl : public PolicyManager { std::vector<std::string>& enabled_apps) const OVERRIDE; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * @ brief Initialize new cloud app in the policy table @@ -921,6 +907,10 @@ class PolicyManagerImpl : public PolicyManager { */ void OnSystemRequestReceived() OVERRIDE; + void OnLocalAppAdded() OVERRIDE; + + bool IsNewApplication(const std::string& application_id) const OVERRIDE; + protected: /** * @brief Parse policy table content and convert to PT object @@ -1037,13 +1027,6 @@ class PolicyManagerImpl : public PolicyManager { DeviceConsent device_consent); /** - * @brief Check if certain application already in policy db. - * @param policy application id. - * @return true if application presents false otherwise. - */ - bool IsNewApplication(const std::string& application_id) const; - - /** * Checks existing and permissions of AppStorageFolder * @return true if AppStorageFolder exists and has permissions read/write */ @@ -1124,6 +1107,9 @@ class PolicyManagerImpl : public PolicyManager { void SendAppPermissionsChanged(const std::string& device_id, const std::string& application_id) OVERRIDE; + void SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const OVERRIDE; + /** * @brief notify listener of updated auth token for a given policy id * @param policy_app_id the app id that has an updated auth token @@ -1341,6 +1327,8 @@ class PolicyManagerImpl : public PolicyManager { */ bool send_on_update_sent_out_; + std::vector<std::string> app_properties_changed_list_; + /** * @brief Flag for notifying that invalid PTU should be triggered */ 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 879eb0aa9b..7e8abd5989 100644 --- a/src/components/policy/policy_external/include/policy/policy_types.h +++ b/src/components/policy/policy_external/include/policy/policy_types.h @@ -232,8 +232,11 @@ struct DeviceInfo { using namespace helpers; static const std::string bluetooth("BLUETOOTH"); static const std::string wifi("WIFI"); + static const std::string webengine("WEBENGINE_WEBSOCKET"); if (Compare<std::string, EQ, ONE>(deviceType, bluetooth, wifi)) { connection_type.assign("BTMAC"); + } else if (Compare<std::string, EQ, ONE>(deviceType, webengine)) { + connection_type.assign(""); } } }; @@ -452,11 +455,13 @@ struct ApplicationPolicyActions { ApplicationPolicyActions() : is_notify_system(false) , is_send_permissions_to_app(false) - , is_consent_needed(false) {} + , is_consent_needed(false) + , app_properties_changed(false) {} bool is_notify_system; bool is_send_permissions_to_app; bool is_consent_needed; + bool app_properties_changed; }; /** @@ -517,6 +522,7 @@ enum PermissionsCheckResult { RESULT_REQUEST_TYPE_CHANGED, RESULT_REQUEST_SUBTYPE_CHANGED, RESULT_ENCRYPTION_REQUIRED_FLAG_CHANGED, + RESULT_APP_PROPERTIES_CHANGED }; /** @@ -539,6 +545,68 @@ enum ConsentPriorityType { kUserConsentPrio, kExternalConsentPrio }; */ enum ConsentProcessingPolicy { kTimestampBased, kExternalConsentBased }; +/** + * @brief The AppProperties struct contains application properties + */ +struct AppProperties { + AppProperties() + : endpoint() + , certificate() + , enabled(false) + , auth_token() + , transport_type() + , hybrid_app_preference() {} + + AppProperties(std::string endpoint, + std::string certificate, + bool enabled, + std::string auth_token, + std::string transport_type, + std::string hybrid_app_preference) + : endpoint(endpoint) + , certificate(certificate) + , enabled(enabled) + , auth_token(auth_token) + , transport_type(transport_type) + , hybrid_app_preference(hybrid_app_preference) {} + + /** + * @brief endpoint Filled with the endpoint used to connect to the cloud + * application. + * @note should be absent for local applications + */ + std::string endpoint; + + /** + * @brief certificate Filled with the certificate used for creation + * of a secure connection to the cloud application + */ + std::string certificate; + + /** + * @brief enabled Whether or not the app is enabled + */ + bool enabled; + + /** + * @brief auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + */ + std::string auth_token; + + /** + * @brief transport_type Filled with the transport type used by the + * cloud/local application (ex. "WSS") + */ + std::string transport_type; + + /** + * @brief hybrid_app_preference Filled with the hybrid app preference for the + * application set by the user + */ + std::string hybrid_app_preference; +}; + } // namespace policy #endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_ diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 5bf4bfd658..a49d450a9e 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1471,40 +1471,60 @@ void CacheManager::GetEnabledCloudApps( #endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT } -bool CacheManager::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { +bool CacheManager::GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const { const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = policies.find(policy_app_id); if (policies.end() != policy_iter) { auto app_policy = (*policy_iter).second; - endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint - : std::string(); - auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token - : std::string(); - cloud_transport_type = app_policy.cloud_transport_type.is_initialized() - ? *app_policy.cloud_transport_type - : std::string(); - certificate = app_policy.certificate.is_initialized() - ? *app_policy.certificate - : std::string(); - hybrid_app_preference = + out_app_properties.endpoint = app_policy.endpoint.is_initialized() + ? *app_policy.endpoint + : std::string(); + out_app_properties.auth_token = app_policy.auth_token.is_initialized() + ? *app_policy.auth_token + : std::string(); + out_app_properties.transport_type = + app_policy.cloud_transport_type.is_initialized() + ? *app_policy.cloud_transport_type + : std::string(); + out_app_properties.certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); + out_app_properties.hybrid_app_preference = app_policy.hybrid_app_preference.is_initialized() ? EnumToJsonString(*app_policy.hybrid_app_preference) : std::string(); - enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; + out_app_properties.enabled = + app_policy.enabled.is_initialized() && *app_policy.enabled; return true; } return false; } +std::vector<std::string> CacheManager::GetEnabledLocalApps() const { +#if !defined(WEBSOCKET_SERVER_TRANSPORT_SUPPORT) + return std::vector<std::string>(); +#else + std::vector<std::string> enabled_apps; + const policy_table::ApplicationPolicies& app_policies = + pt_->policy_table.app_policies_section.apps; + for (const auto& app_policies_item : app_policies) { + const auto app_policy = app_policies_item.second; + // Local (WebEngine) applications + // should not have "endpoint" field + if (app_policy.endpoint.is_initialized()) { + continue; + } + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back(app_policies_item.first); + } + } + return enabled_apps; +#endif // WEBSOCKET_SERVER_TRANSPORT_SUPPORT +} + void CacheManager::InitCloudApp(const std::string& policy_app_id) { CACHE_MANAGER_CHECK_VOID(); sync_primitives::AutoLock auto_lock(cache_lock_); diff --git a/src/components/policy/policy_external/src/policy_helper.cc b/src/components/policy/policy_external/src/policy_helper.cc index 98e5b5b3c1..b8bbb1682c 100644 --- a/src/components/policy/policy_external/src/policy_helper.cc +++ b/src/components/policy/policy_external/src/policy_helper.cc @@ -434,6 +434,13 @@ void CheckAppPolicy::InsertPermission(const std::string& app_id, bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { const std::string app_id = app_policy.first; + + const bool app_properties_changed = IsAppPropertiesChanged(app_policy); + const bool is_predefined_app = IsPredefinedApp(app_policy); + if (!is_predefined_app && app_properties_changed) { + AddResult(app_id, RESULT_APP_PROPERTIES_CHANGED); + } + AppPermissions permissions_diff(app_id); if (!IsKnownAppication(app_id)) { LOG4CXX_WARN(logger_, @@ -668,6 +675,74 @@ bool CheckAppPolicy::IsRequestSubTypeChanged( return diff.size(); } +bool CheckAppPolicy::IsAppPropertiesProvided( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + if (app_policy.second.hybrid_app_preference.is_initialized() || + app_policy.second.endpoint.is_initialized() || + app_policy.second.enabled.is_initialized() || + app_policy.second.auth_token.is_initialized() || + app_policy.second.cloud_transport_type.is_initialized() || + app_policy.second.nicknames.is_initialized()) { + return true; + } + return false; +} + +bool CheckAppPolicy::IsAppPropertiesChanged( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + + if (!IsAppPropertiesProvided(app_policy)) { + return false; + } + + if (!IsKnownAppication(app_policy.first)) { + LOG4CXX_DEBUG( + logger_, + "AppProperties provided for new application: " << app_policy.first); + return true; + } + + policy::AppPoliciesConstItr it = + snapshot_->policy_table.app_policies_section.apps.find(app_policy.first); + const auto snapshot_properties = *it; + + if (app_policy.second.enabled.is_initialized() && + app_policy.second.enabled != snapshot_properties.second.enabled) { + LOG4CXX_DEBUG(logger_, "\"enabled\" was changed"); + return true; + } + + if (app_policy.second.endpoint.is_initialized() && + app_policy.second.endpoint != snapshot_properties.second.endpoint) { + LOG4CXX_DEBUG(logger_, "\"endpoint\" was changed"); + return true; + } + + if (app_policy.second.hybrid_app_preference.is_initialized() && + app_policy.second.hybrid_app_preference != + snapshot_properties.second.hybrid_app_preference) { + LOG4CXX_DEBUG(logger_, "\"hybrid_app_preference\" was changed"); + return true; + } + + if (app_policy.second.auth_token.is_initialized() && + app_policy.second.auth_token != snapshot_properties.second.auth_token) { + LOG4CXX_DEBUG(logger_, "\"auth_token\" was changed"); + return true; + } + + if (app_policy.second.cloud_transport_type.is_initialized() && + app_policy.second.cloud_transport_type != + snapshot_properties.second.cloud_transport_type) { + LOG4CXX_DEBUG(logger_, "\"cloud_transport_type\" was changed"); + return true; + } + + return false; +} + bool CheckAppPolicy::IsEncryptionRequiredFlagChanged( const AppPoliciesValueType& app_policy) const { LOG4CXX_AUTO_TRACE(logger_); @@ -778,6 +853,9 @@ void FillActionsForAppPolicies::operator()( case RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED: actions_[app_id].is_consent_needed = true; break; + case RESULT_APP_PROPERTIES_CHANGED: + actions_[app_id].app_properties_changed = true; + break; case RESULT_CONSENT_NOT_REQUIRED: case RESULT_PERMISSIONS_REVOKED: case RESULT_REQUEST_TYPE_CHANGED: 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 787e65f43a..cd2bd4c2d4 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -622,6 +622,10 @@ void PolicyManagerImpl::ProcessActionsForAppPolicies( continue; } + if (action.second.app_properties_changed) { + app_properties_changed_list_.push_back(app_policy->first); + } + const auto devices_ids = listener()->GetDevicesIds(app_policy->first); for (const auto& device_id : devices_ids) { if (action.second.is_consent_needed) { @@ -820,21 +824,13 @@ void PolicyManagerImpl::GetEnabledCloudApps( cache_->GetEnabledCloudApps(enabled_apps); } -bool PolicyManagerImpl::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); +std::vector<std::string> PolicyManagerImpl::GetEnabledLocalApps() const { + return cache_->GetEnabledLocalApps(); +} + +bool PolicyManagerImpl::GetAppProperties( + const std::string& policy_app_id, AppProperties& out_app_properties) const { + return cache_->GetAppProperties(policy_app_id, out_app_properties); } void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) { @@ -1201,6 +1197,12 @@ void PolicyManagerImpl::AddDevice(const std::string& device_id, } } +void PolicyManagerImpl::OnLocalAppAdded() { + LOG4CXX_AUTO_TRACE(logger_); + update_status_manager_.ScheduleUpdate(); + StartPTExchange(); +} + void PolicyManagerImpl::SetDeviceInfo(const std::string& device_id, const DeviceInfo& device_info) { LOG4CXX_AUTO_TRACE(logger_); @@ -1702,6 +1704,12 @@ void PolicyManagerImpl::UpdateAppConsentWithExternalConsent( cache_->SetExternalConsentForApp(updated_external_consent_permissions); } +void PolicyManagerImpl::SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + listener_->SendOnAppPropertiesChangeNotification(policy_app_id); +} + void PolicyManagerImpl::ResumePendingAppPolicyActions() { LOG4CXX_AUTO_TRACE(logger_); @@ -1714,6 +1722,10 @@ void PolicyManagerImpl::ResumePendingAppPolicyActions() { SendPermissionsToApp(send_permissions_params.first, send_permissions_params.second); } + + for (auto& app : app_properties_changed_list_) { + SendOnAppPropertiesChangeNotification(app); + } send_permissions_list_.clear(); } @@ -2318,10 +2330,10 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, const bool ret = cache_->Init(file_name, settings); if (ret) { RefreshRetrySequence(); - std::vector<std::string> enabled_apps; - cache_->GetEnabledCloudApps(enabled_apps); - for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { - SendAuthTokenUpdated(*it); + std::vector<std::string> enabled_cloud_apps; + cache_->GetEnabledCloudApps(enabled_cloud_apps); + for (auto app : enabled_cloud_apps) { + SendAuthTokenUpdated(app); } } return ret; @@ -2440,12 +2452,9 @@ void PolicyManagerImpl::SendAppPermissionsChanged( } void PolicyManagerImpl::SendAuthTokenUpdated(const std::string policy_app_id) { - bool enabled = false; - std::string end, cert, ctt, hap; - std::string auth_token; - cache_->GetCloudAppParameters( - policy_app_id, enabled, end, cert, auth_token, ctt, hap); - listener_->OnAuthTokenUpdated(policy_app_id, auth_token); + AppProperties app_properties; + cache_->GetAppProperties(policy_app_id, app_properties); + listener_->OnAuthTokenUpdated(policy_app_id, app_properties.auth_token); } void PolicyManagerImpl::OnPrimaryGroupsChanged( 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 4fbbeaa6aa..920d2e1272 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 @@ -146,9 +146,6 @@ TEST_F(PolicyManagerImplTest2, IsAppRevoked_SetRevokedAppID_ExpectAppRevoked) { // Arrange CreateLocalPT(preloaded_pt_filename_); - EXPECT_CALL(listener_, GetDevicesIds(app_id_1_)) - .WillRepeatedly(Return(transport_manager::DeviceList())); - policy_manager_->AddApplication( device_id_1_, app_id_1_, HmiTypes(policy_table::AHT_DEFAULT)); @@ -224,8 +221,10 @@ TEST_F(PolicyManagerImplTest2, EXPECT_CALL(listener_, OnCurrentDeviceIdUpdateRequired(_, app_id_1_)) .Times(0); - EXPECT_CALL(listener_, GetDevicesIds(app_id_1_)) - .WillRepeatedly(Return(transport_manager::DeviceList(1, device_id_1_))); + ON_CALL(listener_, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); + ON_CALL(listener_, GetDevicesIds(app_id_1_)) + .WillByDefault(Return(transport_manager::DeviceList(1, device_id_1_))); policy_manager_->SetUserConsentForDevice(device_id_1_, true); // Add app from consented device. App will be assigned with default policies @@ -289,8 +288,12 @@ TEST_F(PolicyManagerImplTest2, "Bluetooth")); EXPECT_CALL(listener_, OnCurrentDeviceIdUpdateRequired(_, application_id_)) .Times(0); - EXPECT_CALL(listener_, GetDevicesIds(application_id_)) - .WillRepeatedly(Return(transport_manager::DeviceList(1, device_id_1_))); + + ON_CALL(listener_, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); + ON_CALL(listener_, GetDevicesIds(app_id_1_)) + .WillByDefault(Return(transport_manager::DeviceList(1, device_id_1_))); + policy_manager_->SetUserConsentForDevice(device_id_1_, true); // Add app from consented device. App will be assigned with default policies policy_manager_->AddApplication( 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 9f363a223a..dc1d7a06ef 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 @@ -257,6 +257,8 @@ void PolicyManagerImplTest2::SetUp() { ON_CALL(listener_, GetRegisteredLinks(_)).WillByDefault(Return()); ON_CALL(listener_, ptu_retry_handler()) .WillByDefault(ReturnRef(ptu_retry_handler_)); + ON_CALL(listener_, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); file_system::CreateDirectory(app_storage_folder_); @@ -675,6 +677,8 @@ PolicyManagerImplTest_RequestTypes::PolicyManagerImplTest_RequestTypes() void PolicyManagerImplTest_RequestTypes::SetUp() { ON_CALL(listener_, GetRegisteredLinks(_)).WillByDefault(Return()); + ON_CALL(listener_, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); file_system::CreateDirectory(app_storage_folder_); const bool in_memory = true; diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index 6bd2c4840b..0ad7634382 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -161,6 +161,7 @@ class CacheManager : public CacheManagerInterface { const boost::optional<std::string> LockScreenDismissalWarningMessage( const std::string& language) const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled @@ -170,28 +171,14 @@ class CacheManager : public CacheManagerInterface { std::vector<std::string>& enabled_apps) const; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * Initializes a new cloud application with default policies diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index a1b4af0f39..35a61f6597 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -177,29 +177,21 @@ class CacheManagerInterface { std::vector<std::string>& enabled_apps) const = 0; /** - * @brief Get cloud app policy information, all fields that aren't set for a + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + virtual std::vector<std::string> GetEnabledLocalApps() const = 0; + + /** + * @brief Get app policy information, all fields that aren't set for a * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const = 0; + * @param policy_app_id policy app id + * @param out_app_properties application properties + * @return true if application presents in database, otherwise - false + */ + virtual bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const = 0; /** * Initializes a new cloud application with default policies diff --git a/src/components/policy/policy_regular/include/policy/policy_helper.h b/src/components/policy/policy_regular/include/policy/policy_helper.h index a8cec41715..d5155cf91b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_helper.h +++ b/src/components/policy/policy_regular/include/policy/policy_helper.h @@ -131,6 +131,10 @@ struct CheckAppPolicy { bool IsEncryptionRequiredFlagChanged( const AppPoliciesValueType& app_policy) const; + bool IsAppPropertiesChanged(const AppPoliciesValueType& app_policy) const; + + bool IsAppPropertiesProvided(const AppPoliciesValueType& app_policy) const; + private: PolicyManagerImpl* pm_; const std::shared_ptr<policy_table::Table> update_; diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 192de6cd34..a1a39ff80b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -671,6 +671,7 @@ class PolicyManagerImpl : public PolicyManager { * @return policy_table as json object */ Json::Value GetPolicyTableData() const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled @@ -680,28 +681,14 @@ class PolicyManagerImpl : public PolicyManager { std::vector<std::string>& enabled_apps) const OVERRIDE; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * @ brief Initialize new cloud app in the policy table @@ -876,6 +863,10 @@ class PolicyManagerImpl : public PolicyManager { int32_t timespan_seconds) OVERRIDE; // Interface StatisticsManager (end) + void OnLocalAppAdded() OVERRIDE; + + bool IsNewApplication(const std::string& application_id) const OVERRIDE; + void ResetTimeout() OVERRIDE; protected: @@ -984,13 +975,6 @@ class PolicyManagerImpl : public PolicyManager { DeviceConsent device_consent); /** - * @brief Check if certain application already in policy db. - * @param policy application id. - * @return true if application presents false otherwise. - */ - bool IsNewApplication(const std::string& application_id) const; - - /** * Checks existing and permissions of AppStorageFolder * @return true if AppStorageFolder exists and has permissions read/write */ @@ -1077,6 +1061,9 @@ class PolicyManagerImpl : public PolicyManager { void SendAppPermissionsChanged(const std::string& device_id, const std::string& application_id) OVERRIDE; + void SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const OVERRIDE; + /** * @brief notify listener of updated auth token for a given policy id * @param policy_app_id the app id that has an updated auth token @@ -1185,6 +1172,11 @@ class PolicyManagerImpl : public PolicyManager { bool send_on_update_sent_out_; /** + * @brief List of chnaged application properties + */ + std::vector<std::string> app_properties_changed_list_; + + /** * @brief Flag for notifying that invalid PTU should be triggered */ bool trigger_ptu_; diff --git a/src/components/policy/policy_regular/include/policy/policy_types.h b/src/components/policy/policy_regular/include/policy/policy_types.h index f8d71ecb13..7f95d9132b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_types.h +++ b/src/components/policy/policy_regular/include/policy/policy_types.h @@ -234,8 +234,11 @@ struct DeviceInfo { using namespace helpers; static const std::string bluetooth("BLUETOOTH"); static const std::string wifi("WIFI"); + static const std::string webengine("WEBENGINE_WEBSOCKET"); if (Compare<std::string, EQ, ONE>(deviceType, bluetooth, wifi)) { connection_type.assign("BTMAC"); + } else if (Compare<std::string, EQ, ONE>(deviceType, webengine)) { + connection_type.assign(""); } } }; @@ -444,11 +447,13 @@ struct ApplicationPolicyActions { ApplicationPolicyActions() : is_notify_system(false) , is_send_permissions_to_app(false) - , is_consent_needed(false) {} + , is_consent_needed(false) + , app_properties_changed(false) {} bool is_notify_system; bool is_send_permissions_to_app; bool is_consent_needed; + bool app_properties_changed; }; /** @@ -508,7 +513,8 @@ enum PermissionsCheckResult { RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED, RESULT_REQUEST_TYPE_CHANGED, RESULT_REQUEST_SUBTYPE_CHANGED, - RESULT_ENCRYPTION_REQUIRED_FLAG_CHANGED + RESULT_ENCRYPTION_REQUIRED_FLAG_CHANGED, + RESULT_APP_PROPERTIES_CHANGED }; /** @@ -524,6 +530,68 @@ typedef std::set<std::pair<std::string, PermissionsCheckResult> > */ typedef std::pair<uint32_t, uint32_t> AppIdURL; +/** + * @brief The AppProperties struct contains application properties + */ +struct AppProperties { + AppProperties() + : endpoint() + , certificate() + , enabled(false) + , auth_token() + , transport_type() + , hybrid_app_preference() {} + + AppProperties(std::string endpoint, + std::string certificate, + bool enabled, + std::string auth_token, + std::string transport_type, + std::string hybrid_app_preference) + : endpoint(endpoint) + , certificate(certificate) + , enabled(enabled) + , auth_token(auth_token) + , transport_type(transport_type) + , hybrid_app_preference(hybrid_app_preference) {} + + /** + * @brief endpoint Filled with the endpoint used to connect to the cloud + * application. + * @note should be absent for local applications + */ + std::string endpoint; + + /** + * @brief certificate Filled with the certificate used for creation + * of a secure connection to the cloud application + */ + std::string certificate; + + /** + * @brief enabled Whether or not the app is enabled + */ + bool enabled; + + /** + * @brief auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + */ + std::string auth_token; + + /** + * @brief transport_type Filled with the transport type used by the + * cloud/local application (ex. "WSS") + */ + std::string transport_type; + + /** + * @brief hybrid_app_preference Filled with the hybrid app preference for the + * application set by the user + */ + std::string hybrid_app_preference; +}; + } // namespace policy #endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_ diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 743b9eff6c..7a6f98f536 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -766,35 +766,55 @@ void CacheManager::GetEnabledCloudApps( #endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT } -bool CacheManager::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { +std::vector<std::string> CacheManager::GetEnabledLocalApps() const { +#if !defined(WEBSOCKET_SERVER_TRANSPORT_SUPPORT) + return std::vector<std::string>(); +#else + std::vector<std::string> enabled_apps; + const policy_table::ApplicationPolicies& app_policies = + pt_->policy_table.app_policies_section.apps; + for (const auto& app_policies_item : app_policies) { + const auto app_policy = app_policies_item.second; + // Local (WebEngine) applications + // should not have "endpoint" field + if (app_policy.endpoint.is_initialized()) { + continue; + } + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back(app_policies_item.first); + } + } + return enabled_apps; +#endif // WEBSOCKET_SERVER_TRANSPORT_SUPPORT +} + +bool CacheManager::GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const { const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = policies.find(policy_app_id); if (policies.end() != policy_iter) { auto app_policy = (*policy_iter).second; - endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint - : std::string(); - auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token - : std::string(); - cloud_transport_type = app_policy.cloud_transport_type.is_initialized() - ? *app_policy.cloud_transport_type - : std::string(); - certificate = app_policy.certificate.is_initialized() - ? *app_policy.certificate - : std::string(); - hybrid_app_preference = + out_app_properties.endpoint = app_policy.endpoint.is_initialized() + ? *app_policy.endpoint + : std::string(); + out_app_properties.auth_token = app_policy.auth_token.is_initialized() + ? *app_policy.auth_token + : std::string(); + out_app_properties.transport_type = + app_policy.cloud_transport_type.is_initialized() + ? *app_policy.cloud_transport_type + : std::string(); + out_app_properties.certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); + out_app_properties.hybrid_app_preference = app_policy.hybrid_app_preference.is_initialized() ? EnumToJsonString(*app_policy.hybrid_app_preference) : std::string(); - enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; + out_app_properties.enabled = + app_policy.enabled.is_initialized() && *app_policy.enabled; return true; } return false; diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc index b689ed81ba..08f1fbb177 100644 --- a/src/components/policy/policy_regular/src/policy_helper.cc +++ b/src/components/policy/policy_regular/src/policy_helper.cc @@ -388,6 +388,12 @@ void CheckAppPolicy::AddResult(const std::string& app_id, bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { const std::string app_id = app_policy.first; + const bool app_properties_changed = IsAppPropertiesChanged(app_policy); + const bool is_predefined_app = IsPredefinedApp(app_policy); + if (!is_predefined_app && app_properties_changed) { + AddResult(app_id, RESULT_APP_PROPERTIES_CHANGED); + } + if (!IsKnownAppication(app_id)) { LOG4CXX_WARN(logger_, "Application:" << app_id << " is not present in snapshot."); @@ -608,6 +614,74 @@ bool CheckAppPolicy::IsRequestSubTypeChanged( return diff.size(); } +bool CheckAppPolicy::IsAppPropertiesProvided( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + if (app_policy.second.hybrid_app_preference.is_initialized() || + app_policy.second.endpoint.is_initialized() || + app_policy.second.enabled.is_initialized() || + app_policy.second.auth_token.is_initialized() || + app_policy.second.cloud_transport_type.is_initialized() || + app_policy.second.nicknames.is_initialized()) { + return true; + } + return false; +} + +bool CheckAppPolicy::IsAppPropertiesChanged( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + + if (!IsAppPropertiesProvided(app_policy)) { + return false; + } + + if (!IsKnownAppication(app_policy.first)) { + LOG4CXX_DEBUG( + logger_, + "AppProperties provided for new application: " << app_policy.first); + return true; + } + + policy::AppPoliciesConstItr it = + snapshot_->policy_table.app_policies_section.apps.find(app_policy.first); + const auto snapshot_properties = *it; + + if (app_policy.second.enabled.is_initialized() && + app_policy.second.enabled != snapshot_properties.second.enabled) { + LOG4CXX_DEBUG(logger_, "\"enabled\" was changed"); + return true; + } + + if (app_policy.second.endpoint.is_initialized() && + app_policy.second.endpoint != snapshot_properties.second.endpoint) { + LOG4CXX_DEBUG(logger_, "\"endpoint\" was changed"); + return true; + } + + if (app_policy.second.hybrid_app_preference.is_initialized() && + app_policy.second.hybrid_app_preference != + snapshot_properties.second.hybrid_app_preference) { + LOG4CXX_DEBUG(logger_, "\"hybrid_app_preference\" was changed"); + return true; + } + + if (app_policy.second.auth_token.is_initialized() && + app_policy.second.auth_token != snapshot_properties.second.auth_token) { + LOG4CXX_DEBUG(logger_, "\"auth_token\" was changed"); + return true; + } + + if (app_policy.second.cloud_transport_type.is_initialized() && + app_policy.second.cloud_transport_type != + snapshot_properties.second.cloud_transport_type) { + LOG4CXX_DEBUG(logger_, "\"cloud_transport_type\" was changed"); + return true; + } + + return false; +} + bool CheckAppPolicy::IsEncryptionRequiredFlagChanged( const AppPoliciesValueType& app_policy) const { auto get_app_encryption_needed = @@ -699,7 +773,6 @@ void FillActionsForAppPolicies::operator()( const policy::CheckAppPolicyResults::value_type& value) { const std::string app_id = value.first; const auto app_policy = app_policies_.find(app_id); - if (app_policies_.end() == app_policy) { return; } @@ -717,6 +790,9 @@ void FillActionsForAppPolicies::operator()( case RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED: actions_[app_id].is_consent_needed = true; break; + case RESULT_APP_PROPERTIES_CHANGED: + actions_[app_id].app_properties_changed = true; + break; case RESULT_CONSENT_NOT_REQUIRED: case RESULT_PERMISSIONS_REVOKED: case RESULT_REQUEST_TYPE_CHANGED: diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index b93850f579..94c1009086 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -466,6 +466,10 @@ void PolicyManagerImpl::ProcessActionsForAppPolicies( continue; } + if (it_actions->second.app_properties_changed) { + app_properties_changed_list_.push_back(app_policy->first); + } + const auto devices_ids = listener()->GetDevicesIds(app_policy->first); for (const auto& device_id : devices_ids) { if (it_actions->second.is_consent_needed) { @@ -493,6 +497,12 @@ void PolicyManagerImpl::ProcessActionsForAppPolicies( } } +void PolicyManagerImpl::SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + listener_->SendOnAppPropertiesChangeNotification(policy_app_id); +} + void PolicyManagerImpl::ResumePendingAppPolicyActions() { LOG4CXX_AUTO_TRACE(logger_); @@ -505,6 +515,11 @@ void PolicyManagerImpl::ResumePendingAppPolicyActions() { SendPermissionsToApp(send_permissions_params.first, send_permissions_params.second); } + + for (auto& app : app_properties_changed_list_) { + SendOnAppPropertiesChangeNotification(app); + } + send_permissions_list_.clear(); } @@ -682,6 +697,12 @@ void PolicyManagerImpl::OnAppsSearchCompleted(const bool trigger_ptu) { } } +void PolicyManagerImpl::OnLocalAppAdded() { + LOG4CXX_AUTO_TRACE(logger_); + update_status_manager_.ScheduleUpdate(); + StartPTExchange(); +} + void PolicyManagerImpl::OnAppRegisteredOnMobile( const std::string& device_id, const std::string& application_id) { StartPTExchange(); @@ -738,21 +759,13 @@ void PolicyManagerImpl::GetEnabledCloudApps( cache_->GetEnabledCloudApps(enabled_apps); } -bool PolicyManagerImpl::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); +std::vector<std::string> PolicyManagerImpl::GetEnabledLocalApps() const { + return cache_->GetEnabledLocalApps(); +} + +bool PolicyManagerImpl::GetAppProperties( + const std::string& policy_app_id, AppProperties& out_app_properties) const { + return cache_->GetAppProperties(policy_app_id, out_app_properties); } void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) { @@ -1581,10 +1594,10 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, if (!certificate_data.empty()) { listener_->OnCertificateUpdated(certificate_data); } - std::vector<std::string> enabled_apps; - cache_->GetEnabledCloudApps(enabled_apps); - for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { - SendAuthTokenUpdated(*it); + std::vector<std::string> enabled_cloud_apps; + cache_->GetEnabledCloudApps(enabled_cloud_apps); + for (auto app : enabled_cloud_apps) { + SendAuthTokenUpdated(app); } } return ret; @@ -1735,12 +1748,9 @@ void PolicyManagerImpl::SendAppPermissionsChanged( } void PolicyManagerImpl::SendAuthTokenUpdated(const std::string policy_app_id) { - bool enabled = false; - std::string end, cert, ctt, hap; - std::string auth_token; - cache_->GetCloudAppParameters( - policy_app_id, enabled, end, cert, auth_token, ctt, hap); - listener_->OnAuthTokenUpdated(policy_app_id, auth_token); + AppProperties app_properties; + cache_->GetAppProperties(policy_app_id, app_properties); + listener_->OnAuthTokenUpdated(policy_app_id, app_properties.auth_token); } void PolicyManagerImpl::OnPrimaryGroupsChanged( diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc index abb5901690..08e8dd4023 100644 --- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc +++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc @@ -1328,6 +1328,8 @@ TEST_F( // Arrange CreateLocalPT("sdl_preloaded_pt.json"); EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); + ON_CALL(listener, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); GetPTU("valid_sdl_pt_update.json"); EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); // Try to add existing app @@ -1342,6 +1344,8 @@ TEST_F(PolicyManagerImplTest2, UpdateApplication_AppServices) { // Arrange CreateLocalPT("sdl_preloaded_pt.json"); EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); + ON_CALL(listener, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); GetPTU("valid_sdl_pt_update.json"); EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); // Try to add existing app @@ -1376,6 +1380,8 @@ TEST_F(PolicyManagerImplTest2, const int kSecondsInDay = 60 * 60 * 24; int days = date_time::getSecs(current_time) / kSecondsInDay; EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); + ON_CALL(listener, GetDevicesIds(_)) + .WillByDefault(Return(transport_manager::DeviceList())); GetPTU("valid_sdl_pt_update.json"); EXPECT_EQ("UP_TO_DATE", manager->GetPolicyTableStatus()); |