diff options
Diffstat (limited to 'src')
22 files changed, 256 insertions, 29 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 7eb2d43d84..a599581062 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -1610,6 +1610,8 @@ class ApplicationManagerImpl uint32_t apps_size_; + bool is_registered_in_timeout_; + volatile bool is_stopping_; std::unique_ptr<CommandHolder> commands_holder_; 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 a03288f9a9..dd25c48403 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 @@ -183,9 +183,7 @@ class PolicyHandler : public PolicyHandlerInterface, const std::string& policy_app_id, const std::string& hmi_level) OVERRIDE; -#ifndef EXTERNAL_PROPRIETARY_MODE - void OnPTUTimeOut() OVERRIDE; -#endif + void OnPTUTimeOut(); /** * Gets all allowed module types * @param app_id unique identifier of application @@ -424,6 +422,18 @@ class PolicyHandler : public PolicyHandlerInterface, */ uint32_t GetAppIdForSending() const OVERRIDE; + /** + * @brief Add application to PTU queue if don't have application + * with the same app_id + * @param new_app_id app id new application + */ + void AddNewApplicationIdToPTUQueue(const uint32_t new_app_id); + + /** + * @brief Remove first from queue application + */ + void RemoveApplicationFromPTUQueue(); + custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; @@ -586,6 +596,19 @@ class PolicyHandler : public PolicyHandlerInterface, void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; /** + * @brief New application was added to application list + * @param new_app_id app_id for this application + * @param policy_id policy_id for this application + */ + void OnAddedNewApplicationToAppList(const uint32_t new_app_id, + const std::string policy_id) OVERRIDE; + + /** + * @brief Application queue ready for PTU + */ + std::vector<uint32_t> queue_applications_for_ptu_; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. @@ -896,6 +919,8 @@ class PolicyHandler : public PolicyHandlerInterface, std::shared_ptr<StatisticManagerImpl> statistic_manager_impl_; const PolicySettings& settings_; application_manager::ApplicationManager& application_manager_; + std::string last_registered_app_id_; + friend class AppPermissionDelegate; /** diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 471348c119..459dfab7eb 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -196,6 +196,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( this, &ApplicationManagerImpl::ClearTimerPool)) , is_low_voltage_(false) , apps_size_(0) + , is_registered_in_timeout_(false) , is_stopping_(false) { std::srand(std::time(nullptr)); AddPolicyObserver(this); @@ -3827,7 +3828,7 @@ bool ApplicationManagerImpl::IsHMICooperating() const { void ApplicationManagerImpl::OnApplicationListUpdateTimer() { LOG4CXX_DEBUG(logger_, "Application list update timer finished"); - + is_registered_in_timeout_ = false; apps_to_register_list_lock_ptr_->Acquire(); const bool trigger_ptu = apps_size_ != applications_.size(); apps_to_register_list_lock_ptr_->Release(); @@ -4289,6 +4290,12 @@ void ApplicationManagerImpl::AddAppToRegisteredAppList( logger_, "App with app_id: " << application->app_id() << " has been added to registered applications list"); + if (application_list_update_timer_.is_running() && + !is_registered_in_timeout_) { + GetPolicyHandler().OnAddedNewApplicationToAppList( + application->app_id(), application->policy_app_id()); + is_registered_in_timeout_ = true; + } apps_size_ = static_cast<uint32_t>(applications_.size()); } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 64e15d7134..eddd8b2b9f 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -301,7 +301,8 @@ PolicyHandler::PolicyHandler(const PolicySettings& settings, , last_activated_app_id_(0) , statistic_manager_impl_(std::make_shared<StatisticManagerImpl>(this)) , settings_(settings) - , application_manager_(application_manager) {} + , application_manager_(application_manager) + , last_registered_app_id_("") {} PolicyHandler::~PolicyHandler() {} @@ -465,6 +466,28 @@ uint32_t PolicyHandler::GetAppIdForSending() const { return ChooseRandomAppForPolicyUpdate(apps_with_none_level); } +void PolicyHandler::AddNewApplicationIdToPTUQueue(const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + + if (std::find(queue_applications_for_ptu_.begin(), + queue_applications_for_ptu_.end(), + app_id) == queue_applications_for_ptu_.end()) { + queue_applications_for_ptu_.push_back(app_id); + policy_manager_->OnChangeApplicationCount( + queue_applications_for_ptu_.size()); + } +} + +void PolicyHandler::RemoveApplicationFromPTUQueue() { + LOG4CXX_AUTO_TRACE(logger_); + + if (queue_applications_for_ptu_.size() > 0) { + queue_applications_for_ptu_.erase(queue_applications_for_ptu_.begin()); + policy_manager_->OnChangeApplicationCount( + queue_applications_for_ptu_.size()); + } +} + #ifdef EXTERNAL_PROPRIETARY_MODE PTURetryHandler& PolicyHandler::ptu_retry_handler() const { LOG4CXX_AUTO_TRACE(logger_); @@ -1123,7 +1146,7 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file, const bool is_ptu_successful = load_pt_result == PolicyManager::PtProcessingResult::kSuccess; OnPTUFinished(is_ptu_successful); - + RemoveApplicationFromPTUQueue(); if (is_ptu_successful) { LOG4CXX_INFO(logger_, "PTU was successful."); policy_manager_->CleanupUnpairedDevices(); @@ -1499,11 +1522,12 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, << policy_app_id << " and connection_key " << app->app_id()); } -#ifndef EXTERNAL_PROPRIETARY_MODE void PolicyHandler::OnPTUTimeOut() { + RemoveApplicationFromPTUQueue(); +#ifndef EXTERNAL_PROPRIETARY_MODE application_manager_.protocol_handler().ProcessFailedPTU(); -} #endif +} bool PolicyHandler::SaveSnapshot(const BinaryMessage& pt_string, std::string& snap_path) { @@ -1546,9 +1570,11 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string, POLICY_LIB_CHECK_VOID(); #ifdef PROPRIETARY_MODE std::string policy_snapshot_full_path; - if (!SaveSnapshot(pt_string, policy_snapshot_full_path)) { - LOG4CXX_ERROR(logger_, "Snapshot processing skipped."); - return; + if (PTUIterationType::RetryIteration != iteration_type) { + if (!SaveSnapshot(pt_string, policy_snapshot_full_path)) { + LOG4CXX_ERROR(logger_, "Snapshot processing skipped."); + return; + } } if (PTUIterationType::RetryIteration == iteration_type) { @@ -1912,7 +1938,9 @@ void PolicyHandler::OnAuthTokenUpdated(const std::string& policy_app_id, void PolicyHandler::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(listeners_lock_); - + if (!ptu_result) { + RemoveApplicationFromPTUQueue(); + } std::for_each( listeners_.begin(), listeners_.end(), @@ -2210,6 +2238,15 @@ void PolicyHandler::OnAppsSearchCompleted(const bool trigger_ptu) { policy_manager_->OnAppsSearchCompleted(trigger_ptu); } +void PolicyHandler::OnAddedNewApplicationToAppList( + const uint32_t new_app_id, const std::string policy_id) { + if (last_registered_app_id_ == policy_id) { + return; + } + last_registered_app_id_ = policy_id; + AddNewApplicationIdToPTUQueue(new_app_id); +} + void PolicyHandler::OnAppRegisteredOnMobile(const std::string& device_id, const std::string& application_id) { POLICY_LIB_CHECK_VOID(); diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index 3af3b770aa..d304521fe2 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -411,6 +411,14 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; /** + * @brief Notify that new applocation was added to application list + * @param new_app_id app_id for this application + * @param policy_id policy_id for this application + */ + virtual void OnAddedNewApplicationToAppList(const uint32_t new_app_id, + const std::string policy_id) = 0; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 22721841aa..be748caf02 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -534,6 +534,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; /** + * @brief Change applicatios count ready for PTU + * @param new_app_count new applications count for PTU + */ + virtual void OnChangeApplicationCount(const uint32_t new_app_count) = 0; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index c9143d6bbb..bc546ed98c 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -525,6 +525,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; /** + * @brief Change applicatios count ready for PTU + * @param new_app_count new applications count for PTU + */ + virtual void OnChangeApplicationCount(const uint32_t new_app_count) = 0; + + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id * @return request type state diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index f6e0b3cb0f..57b95e8785 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -219,6 +219,8 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_CONST_METHOD1(HeartBeatTimeout, uint32_t(const std::string& app_id)); MOCK_METHOD0(OnAppsSearchStarted, void()); MOCK_METHOD1(OnAppsSearchCompleted, void(const bool trigger_ptu)); + MOCK_METHOD2(OnAddedNewApplicationToAppList, + void(const uint32_t new_app_id, const std::string policy_id)); MOCK_METHOD2(OnAppRegisteredOnMobile, void(const std::string& device_id, const std::string& application_id)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index d2023fd3d4..9f93b57813 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -212,6 +212,7 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD1(SaveUpdateStatusRequired, void(bool is_update_needed)); MOCK_METHOD0(OnAppsSearchStarted, void()); MOCK_METHOD1(OnAppsSearchCompleted, void(const bool trigger_ptu)); + MOCK_METHOD1(OnChangeApplicationCount, void(const uint32_t new_app_count)); MOCK_METHOD2(OnAppRegisteredOnMobile, void(const std::string& device_id, const std::string& application_id)); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index da9edb9fe5..27cdc27c4b 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -210,6 +210,7 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD1(SaveUpdateStatusRequired, void(bool is_update_needed)); MOCK_METHOD0(OnAppsSearchStarted, void()); MOCK_METHOD1(OnAppsSearchCompleted, void(const bool trigger_ptu)); + MOCK_METHOD1(OnChangeApplicationCount, void(const uint32_t new_app_count)); MOCK_METHOD2(OnAppRegisteredOnMobile, void(const std::string& device_id, const std::string& application_id)); 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..d244a2c0f5 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 @@ -609,6 +609,12 @@ class PolicyManagerImpl : public PolicyManager { void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; /** + * @brief Change applicatios count ready for PTU + * @param new_app_count new applications count for PTU + */ + void OnChangeApplicationCount(const uint32_t new_app_count) OVERRIDE; + + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id * @return request type state @@ -1097,6 +1103,11 @@ class PolicyManagerImpl : public PolicyManager { policy_table::PolicyTableType type) const; /** + * @brief Check that application for PTU more than zero + */ + bool HasApplicationForPTU(); + + /** * @brief Get resulting RPCs permissions for application which started on * specific device * @param device_id Device id @@ -1308,6 +1319,11 @@ class PolicyManagerImpl : public PolicyManager { uint32_t retry_sequence_index_; /** + * @brief Count application ready for PTU + */ + uint32_t count_application_; + + /** * @brief Lock for guarding retry sequence */ mutable sync_primitives::Lock retry_sequence_lock_; @@ -1347,6 +1363,11 @@ class PolicyManagerImpl : public PolicyManager { bool trigger_ptu_; /** + * @brief Flag for notifying that PTU was requested + */ + bool ptu_requested_; + + /** * @brief Flag that indicates whether a PTU sequence (including retries) is in * progress */ diff --git a/src/components/policy/policy_external/include/policy/status.h b/src/components/policy/policy_external/include/policy/status.h index f51888c853..0b5fb0a094 100644 --- a/src/components/policy/policy_external/include/policy/status.h +++ b/src/components/policy/policy_external/include/policy/status.h @@ -55,7 +55,8 @@ enum UpdateEvent { kPendingUpdate, kScheduleManualUpdate, kOnResetRetrySequence, - kNoEvent + kNoEvent, + kPostponedUpdate }; const std::string kUpToDate = "UP_TO_DATE"; diff --git a/src/components/policy/policy_external/include/policy/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h index 9426a26fb8..57ea107103 100644 --- a/src/components/policy/policy_external/include/policy/update_status_manager.h +++ b/src/components/policy/policy_external/include/policy/update_status_manager.h @@ -92,6 +92,11 @@ class UpdateStatusManager { void OnUpdateTimeoutOccurs(); /** + * @brief Postponed update for PTU + */ + void OnUpdatePostponed(); + + /** * @brief Update status handler for valid PTU receiving */ void OnValidUpdateReceived(); 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..773852c354 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -212,8 +212,10 @@ PolicyManagerImpl::PolicyManagerImpl() new AccessRemoteImpl(std::static_pointer_cast<CacheManager>(cache_))) , retry_sequence_timeout_(60) , retry_sequence_index_(0) + , count_application_(0) , ignition_check(true) , retry_sequence_url_(0, 0, "") + , ptu_requested_(false) , is_ptu_in_progress_(false) {} PolicyManagerImpl::PolicyManagerImpl(bool in_memory) @@ -224,10 +226,12 @@ PolicyManagerImpl::PolicyManagerImpl(bool in_memory) new AccessRemoteImpl(std::static_pointer_cast<CacheManager>(cache_))) , retry_sequence_timeout_(60) , retry_sequence_index_(0) + , count_application_(0) , ignition_check(true) , retry_sequence_url_(0, 0, "") , send_on_update_sent_out_(false) , trigger_ptu_(false) + , ptu_requested_(false) , is_ptu_in_progress_(false) {} void PolicyManagerImpl::set_listener(PolicyListener* listener) { @@ -542,6 +546,7 @@ PolicyManager::PtProcessingResult PolicyManagerImpl::LoadPT( void PolicyManagerImpl::OnPTUFinished(const PtProcessingResult ptu_result) { LOG4CXX_AUTO_TRACE(logger_); + ptu_requested_ = false; if (PtProcessingResult::kWrongPtReceived == ptu_result) { LOG4CXX_DEBUG(logger_, "Wrong PT was received"); @@ -551,6 +556,10 @@ void PolicyManagerImpl::OnPTUFinished(const PtProcessingResult ptu_result) { update_status_manager_.OnValidUpdateReceived(); + if (HasApplicationForPTU()) { + update_status_manager_.OnUpdatePostponed(); + } + if (PtProcessingResult::kNewPtRequired == ptu_result) { LOG4CXX_DEBUG(logger_, "New PTU interation is required"); ForcePTExchange(); @@ -709,6 +718,7 @@ void PolicyManagerImpl::RequestPTUpdate() { LOG4CXX_DEBUG(logger_, "Snapshot contents is : " << message_string); BinaryMessage update(message_string.begin(), message_string.end()); + ptu_requested_ = true; listener_->OnSnapshotCreated( update, RetrySequenceDelaysSeconds(), TimeoutExchangeMSec()); @@ -733,7 +743,7 @@ void PolicyManagerImpl::StartPTExchange() { return; } - if (update_status_manager_.IsUpdatePending()) { + if (update_status_manager_.IsUpdatePending() || is_ptu_in_progress_) { if (trigger_ptu_) { update_status_manager_.ScheduleUpdate(); } @@ -763,12 +773,15 @@ void PolicyManagerImpl::OnAppsSearchCompleted(const bool trigger_ptu) { update_status_manager_.OnAppsSearchCompleted(); trigger_ptu_ = trigger_ptu; - - if (update_status_manager_.IsUpdateRequired()) { + if (update_status_manager_.IsUpdateRequired() && !ptu_requested_) { StartPTExchange(); } } +void PolicyManagerImpl::OnChangeApplicationCount(const uint32_t new_app_count) { + count_application_ = new_app_count; +} + const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes( const transport_manager::DeviceHandle& device_handle, const std::string policy_app_id) const { @@ -1382,6 +1395,12 @@ void PolicyManagerImpl::RetrySequenceFailed() { listener_->OnPTUFinished(false); ResetRetrySequence(ResetRetryCountType::kResetWithStatusUpdate); + + if (HasApplicationForPTU()) { + update_status_manager_.OnUpdatePostponed(); + StartPTExchange(); + } + is_ptu_in_progress_ = false; } void PolicyManagerImpl::ResetTimeout() { @@ -1645,6 +1664,10 @@ bool PolicyManagerImpl::IsPTValid( return true; } +bool PolicyManagerImpl::HasApplicationForPTU() { + return count_application_ > 0; +} + const PolicySettings& PolicyManagerImpl::get_settings() const { DCHECK(settings_); return *settings_; @@ -1911,6 +1934,7 @@ void PolicyManagerImpl::IncrementIgnitionCycles() { std::string PolicyManagerImpl::ForcePTExchange() { update_status_manager_.ScheduleUpdate(); + is_ptu_in_progress_ = false; StartPTExchange(); return update_status_manager_.StringifiedUpdateStatus(); } @@ -1959,7 +1983,10 @@ void PolicyManagerImpl::ResetRetrySequence( LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(retry_sequence_lock_); retry_sequence_index_ = 0; - is_ptu_in_progress_ = false; + + if (listener_->CanUpdate()) { + is_ptu_in_progress_ = false; + } if (ResetRetryCountType::kResetWithStatusUpdate == reset_type) { update_status_manager_.OnResetRetrySequence(); } @@ -2082,7 +2109,9 @@ void PolicyManagerImpl::MarkUnpairedDevice(const std::string& device_id) { void PolicyManagerImpl::OnAppRegisteredOnMobile( const std::string& device_id, const std::string& application_id) { - StartPTExchange(); + if (!is_ptu_in_progress_) { + StartPTExchange(); + } SendNotificationOnPermissionsUpdated(device_id, application_id); } @@ -2189,7 +2218,9 @@ StatusNotifier PolicyManagerImpl::AddApplication( } LOG4CXX_DEBUG(logger_, "Promote existed application"); PromoteExistedApplication(device_id, application_id, device_consent); - update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + if (!ptu_requested_) { + update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + } return std::make_shared<utils::CallNothing>(); } diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc index 687bea1c3f..d5e294ccf4 100644 --- a/src/components/policy/policy_external/src/status.cc +++ b/src/components/policy/policy_external/src/status.cc @@ -39,6 +39,9 @@ policy::UpToDateStatus::UpToDateStatus() void policy::UpToDateStatus::ProcessEvent(UpdateStatusManager* manager, policy::UpdateEvent event) { switch (event) { + case kPostponedUpdate: + manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); + break; case kOnNewAppRegistered: case kOnResetPolicyTableRequireUpdate: case kScheduleUpdate: @@ -57,6 +60,9 @@ policy::UpdateNeededStatus::UpdateNeededStatus() void policy::UpdateNeededStatus::ProcessEvent( policy::UpdateStatusManager* manager, policy::UpdateEvent event) { switch (event) { + case kPostponedUpdate: + manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); + break; case kOnUpdateSentOut: manager->SetNextStatus(std::make_shared<UpdatingStatus>()); break; diff --git a/src/components/policy/policy_external/src/update_status_manager.cc b/src/components/policy/policy_external/src/update_status_manager.cc index 3653983c8f..9176afe611 100644 --- a/src/components/policy/policy_external/src/update_status_manager.cc +++ b/src/components/policy/policy_external/src/update_status_manager.cc @@ -87,6 +87,11 @@ void UpdateStatusManager::OnUpdateSentOut(uint32_t update_timeout) { ProcessEvent(kOnUpdateSentOut); } +void UpdateStatusManager::OnUpdatePostponed() { + LOG4CXX_AUTO_TRACE(logger_); + ProcessEvent(kPostponedUpdate); +} + void UpdateStatusManager::OnUpdateTimeoutOccurs() { LOG4CXX_AUTO_TRACE(logger_); 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..5b90a32ae7 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 @@ -625,6 +625,12 @@ class PolicyManagerImpl : public PolicyManager { void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; /** + * @brief Change applicatios count ready for PTU + * @param new_app_count new applications count for PTU + */ + void OnChangeApplicationCount(const uint32_t new_app_count) OVERRIDE; + + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id * @return request type state @@ -1048,6 +1054,11 @@ class PolicyManagerImpl : public PolicyManager { */ void OnPTUIterationTimeout(); + /** + * @brief Check that application for PTU more than zero + */ + bool HasApplicationForPTU(); + private: /** * @brief Get resulting RPCs permissions for application which started on @@ -1146,6 +1157,11 @@ class PolicyManagerImpl : public PolicyManager { uint32_t retry_sequence_index_; /** + * @brief Count application ready for PTU + */ + uint32_t count_application_; + + /** * @brief Lock for guarding retry sequence */ sync_primitives::Lock retry_sequence_lock_; @@ -1189,6 +1205,16 @@ class PolicyManagerImpl : public PolicyManager { */ bool trigger_ptu_; + /** + * @brief Flag for notifying that PTU was requested + */ + bool ptu_requested_; + + /** + * @brief Last registered application id on mobile + */ + std::string last_registered_app_id_; + typedef std::list<std::pair<std::string, AppPoliciesValueType> > PendingAppPolicyActionsList; diff --git a/src/components/policy/policy_regular/include/policy/status.h b/src/components/policy/policy_regular/include/policy/status.h index 8fd3ff559e..ccc53282a8 100644 --- a/src/components/policy/policy_regular/include/policy/status.h +++ b/src/components/policy/policy_regular/include/policy/status.h @@ -54,7 +54,8 @@ enum UpdateEvent { kScheduleUpdate, kScheduleManualUpdate, kOnResetRetrySequence, - kNoEvent + kNoEvent, + kPostponedUpdate }; const std::string kUpToDate = "UP_TO_DATE"; diff --git a/src/components/policy/policy_regular/include/policy/update_status_manager.h b/src/components/policy/policy_regular/include/policy/update_status_manager.h index 0c79bf0ba4..fc96c8bbef 100644 --- a/src/components/policy/policy_regular/include/policy/update_status_manager.h +++ b/src/components/policy/policy_regular/include/policy/update_status_manager.h @@ -213,6 +213,7 @@ class UpdateStatusManager : public UpdateStatusManagerInterface { UpdateEvent last_processed_event_; bool apps_search_in_progress_; bool app_registered_from_non_consented_device_; + bool last_update_was_failed_; sync_primitives::Lock apps_search_in_progress_lock_; }; } // namespace policy 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 22205763a9..1dc6b5c32c 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -70,6 +70,7 @@ PolicyManagerImpl::PolicyManagerImpl() new AccessRemoteImpl(std::static_pointer_cast<CacheManager>(cache_))) , retry_sequence_timeout_(kDefaultRetryTimeoutInMSec) , retry_sequence_index_(0) + , count_application_(0) , timer_retry_sequence_( "Retry sequence timer", new timer::TimerTaskImpl<PolicyManagerImpl>( @@ -77,7 +78,9 @@ PolicyManagerImpl::PolicyManagerImpl() , ignition_check(true) , retry_sequence_url_(0, 0, "") , send_on_update_sent_out_(false) - , trigger_ptu_(false) {} + , trigger_ptu_(false) + , ptu_requested_(false) + , last_registered_app_id_("") {} void PolicyManagerImpl::set_listener(PolicyListener* listener) { listener_ = listener; @@ -411,7 +414,7 @@ PolicyManager::PtProcessingResult PolicyManagerImpl::LoadPT( void PolicyManagerImpl::OnPTUFinished(const PtProcessingResult ptu_result) { LOG4CXX_AUTO_TRACE(logger_); - + ptu_requested_ = false; if (PtProcessingResult::kWrongPtReceived == ptu_result) { LOG4CXX_DEBUG(logger_, "Wrong PT was received"); update_status_manager_.OnWrongUpdateReceived(); @@ -430,7 +433,7 @@ void PolicyManagerImpl::OnPTUFinished(const PtProcessingResult ptu_result) { // If there was a user request for policy table update, it should be started // right after current update is finished - if (update_status_manager_.IsUpdateRequired()) { + if (update_status_manager_.IsUpdateRequired() && HasApplicationForPTU()) { LOG4CXX_DEBUG(logger_, "PTU was successful and new PTU iteration was scheduled"); StartPTExchange(); @@ -607,7 +610,7 @@ bool PolicyManagerImpl::RequestPTUpdate(const PTUIterationType iteration_type) { LOG4CXX_DEBUG(logger_, "Snapshot contents is : " << message_string); BinaryMessage update(message_string.begin(), message_string.end()); - + ptu_requested_ = true; listener_->OnSnapshotCreated(update, iteration_type); return true; } @@ -676,14 +679,23 @@ void PolicyManagerImpl::OnAppsSearchCompleted(const bool trigger_ptu) { trigger_ptu_ = trigger_ptu; - if (update_status_manager_.IsUpdateRequired()) { + if (update_status_manager_.IsUpdateRequired() && !ptu_requested_ && + HasApplicationForPTU()) { StartPTExchange(); } } +void PolicyManagerImpl::OnChangeApplicationCount(const uint32_t new_app_count) { + count_application_ = new_app_count; +} + void PolicyManagerImpl::OnAppRegisteredOnMobile( const std::string& device_id, const std::string& application_id) { - StartPTExchange(); + if (last_registered_app_id_ != application_id) { + StartPTExchange(); + last_registered_app_id_ = application_id; + } + SendNotificationOnPermissionsUpdated(device_id, application_id); } @@ -1257,6 +1269,8 @@ void PolicyManagerImpl::IncrementIgnitionCycles() { std::string PolicyManagerImpl::ForcePTExchange() { update_status_manager_.ScheduleUpdate(); + + ptu_requested_ = false; StartPTExchange(); return update_status_manager_.StringifiedUpdateStatus(); } @@ -1322,6 +1336,9 @@ void PolicyManagerImpl::ResetRetrySequence( LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(retry_sequence_lock_); retry_sequence_index_ = 0; + if (listener_->CanUpdate()) { + ptu_requested_ = false; + } if (ResetRetryCountType::kResetWithStatusUpdate == reset_type) { update_status_manager_.OnResetRetrySequence(); } @@ -1498,7 +1515,9 @@ StatusNotifier PolicyManagerImpl::AddApplication( device_consent); } PromoteExistedApplication(application_id, device_consent); - update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + if (!ptu_requested_) { + update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + } return std::make_shared<utils::CallNothing>(); } @@ -1630,6 +1649,10 @@ void PolicyManagerImpl::OnPTUIterationTimeout() { if (timer_retry_sequence_.is_running()) { timer_retry_sequence_.Stop(); } + + if (HasApplicationForPTU()) { + RequestPTUpdate(PTUIterationType::DefaultIteration); + } return; } @@ -1648,6 +1671,10 @@ void PolicyManagerImpl::OnPTUIterationTimeout() { timer_retry_sequence_.Start(timeout_msec, timer::kPeriodic); } +bool PolicyManagerImpl::HasApplicationForPTU() { + return count_application_ > 0; +} + void PolicyManagerImpl::SetDefaultHmiTypes( const transport_manager::DeviceHandle& device_handle, const std::string& application_id, diff --git a/src/components/policy/policy_regular/src/status.cc b/src/components/policy/policy_regular/src/status.cc index 114ecb9f97..cad403e249 100644 --- a/src/components/policy/policy_regular/src/status.cc +++ b/src/components/policy/policy_regular/src/status.cc @@ -57,6 +57,9 @@ policy::UpdateNeededStatus::UpdateNeededStatus() void policy::UpdateNeededStatus::ProcessEvent( policy::UpdateStatusManagerInterface* manager, policy::UpdateEvent event) { switch (event) { + case kPostponedUpdate: + manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); + break; case kOnUpdateSentOut: manager->SetNextStatus(std::make_shared<UpdatingStatus>()); break; @@ -68,7 +71,6 @@ void policy::UpdateNeededStatus::ProcessEvent( manager->SetNextStatus(std::make_shared<UpToDateStatus>()); break; case kOnNewAppRegistered: - manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); break; default: break; diff --git a/src/components/policy/policy_regular/src/update_status_manager.cc b/src/components/policy/policy_regular/src/update_status_manager.cc index c37f8bbadc..7e5b866dfa 100644 --- a/src/components/policy/policy_regular/src/update_status_manager.cc +++ b/src/components/policy/policy_regular/src/update_status_manager.cc @@ -43,7 +43,8 @@ UpdateStatusManager::UpdateStatusManager() , current_status_(std::make_shared<UpToDateStatus>()) , last_processed_event_(kNoEvent) , apps_search_in_progress_(false) - , app_registered_from_non_consented_device_(true) {} + , app_registered_from_non_consented_device_(true) + , last_update_was_failed_(false) {} UpdateStatusManager::~UpdateStatusManager() {} @@ -97,6 +98,7 @@ void UpdateStatusManager::OnResetDefaultPT(bool is_update_required) { void UpdateStatusManager::OnResetRetrySequence() { LOG4CXX_AUTO_TRACE(logger_); + last_update_was_failed_ = true; ProcessEvent(kOnResetRetrySequence); } @@ -116,6 +118,10 @@ void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) { return; } app_registered_from_non_consented_device_ = false; + if (last_update_was_failed_) { + last_update_was_failed_ = false; + ProcessEvent(kPostponedUpdate); + } ProcessEvent(kOnNewAppRegistered); } |