diff options
author | Yevhenii Dementieiev (GitHub) <57259850+ydementieiev@users.noreply.github.com> | 2020-02-28 22:03:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 15:03:44 -0500 |
commit | ce12181630c0923cf821bfa314d46be02e5380bc (patch) | |
tree | 5116ed78739b31d6bf8b853a0557df92915e133c | |
parent | dd39efa5cf98baba8cf189d2992842f45cef64dc (diff) | |
download | sdl_core-ce12181630c0923cf821bfa314d46be02e5380bc.tar.gz |
Start the new PTU after a failed retry sequence (#3208)
* Start the new PTU after a failed retry sequence in case some trigger occurs during the retry sequence
Co-authored-by: Dmytro Boltovskyi (GitHub) <dboltovskyi@luxoft.com>
20 files changed, 229 insertions, 33 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 1e361a75c9..0bab0243d0 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 @@ -1620,6 +1620,8 @@ class ApplicationManagerImpl uint32_t apps_size_; + std::atomic<bool> registered_during_timer_execution_; + 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 b517a7d82c..eaba6fd5fc 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,8 @@ class PolicyHandler : public PolicyHandlerInterface, const std::string& policy_app_id, const std::string& hmi_level) OVERRIDE; -#ifndef EXTERNAL_PROPRIETARY_MODE void OnPTUTimeOut() OVERRIDE; -#endif + /** * Gets all allowed module types * @param app_id unique identifier of application @@ -424,6 +423,18 @@ class PolicyHandler : public PolicyHandlerInterface, */ uint32_t GetAppIdForSending() const OVERRIDE; + /** + * @brief Add application to PTU queue if no application with + * the same app id exists + * @param new_app_id app id new application + */ + void PushAppIdToPTUQueue(const uint32_t new_app_id); + + /** + * @brief Remove the first application from applications queue + */ + void PopAppIdFromPTUQueue(); + custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; @@ -588,6 +599,14 @@ class PolicyHandler : public PolicyHandlerInterface, */ void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; + void OnAddedNewApplicationToAppList(const uint32_t new_app_id, + const std::string& policy_id) OVERRIDE; + + /** + * @brief Queue applications for which PTU has not yet been completed + */ + std::set<uint32_t> applications_ptu_queue_; + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. @@ -885,6 +904,7 @@ class PolicyHandler : public PolicyHandlerInterface, typedef std::list<PolicyHandlerObserver*> HandlersCollection; HandlersCollection listeners_; mutable sync_primitives::Lock listeners_lock_; + mutable sync_primitives::Lock app_id_queue_lock_; /** * @brief Application-to-device links are used for collecting their current @@ -899,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_policy_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 3b586dd5e7..303dca3b65 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -199,6 +199,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( this, &ApplicationManagerImpl::ClearTimerPool)) , is_low_voltage_(false) , apps_size_(0) + , registered_during_timer_execution_(false) , is_stopping_(false) { std::srand(std::time(nullptr)); AddPolicyObserver(this); @@ -3967,7 +3968,7 @@ bool ApplicationManagerImpl::IsHMICooperating() const { void ApplicationManagerImpl::OnApplicationListUpdateTimer() { LOG4CXX_DEBUG(logger_, "Application list update timer finished"); - + registered_during_timer_execution_ = false; apps_to_register_list_lock_ptr_->Acquire(); const bool trigger_ptu = apps_size_ != applications_.size(); apps_to_register_list_lock_ptr_->Release(); @@ -4429,6 +4430,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() && + !registered_during_timer_execution_) { + GetPolicyHandler().OnAddedNewApplicationToAppList( + application->app_id(), application->policy_app_id()); + registered_during_timer_execution_ = 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 e43281c448..4bbb33b504 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_policy_app_id_(std::string()) {} PolicyHandler::~PolicyHandler() {} @@ -465,6 +466,24 @@ uint32_t PolicyHandler::GetAppIdForSending() const { return ChooseRandomAppForPolicyUpdate(apps_with_none_level); } +void PolicyHandler::PushAppIdToPTUQueue(const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(app_id_queue_lock_); + const auto result = applications_ptu_queue_.insert(app_id); + if (result.second) { + policy_manager_->UpdatePTUReadyAppsCount(applications_ptu_queue_.size()); + } +} + +void PolicyHandler::PopAppIdFromPTUQueue() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(app_id_queue_lock_); + if (applications_ptu_queue_.size() > 0) { + applications_ptu_queue_.erase(applications_ptu_queue_.begin()); + policy_manager_->UpdatePTUReadyAppsCount(applications_ptu_queue_.size()); + } +} + #ifdef EXTERNAL_PROPRIETARY_MODE PTURetryHandler& PolicyHandler::ptu_retry_handler() const { LOG4CXX_AUTO_TRACE(logger_); @@ -1508,11 +1527,13 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, << policy_app_id << " and connection_key " << app->app_id()); } -#ifndef EXTERNAL_PROPRIETARY_MODE + void PolicyHandler::OnPTUTimeOut() { + PopAppIdFromPTUQueue(); +#ifndef EXTERNAL_PROPRIETARY_MODE application_manager_.protocol_handler().ProcessFailedPTU(); -} #endif +} bool PolicyHandler::SaveSnapshot(const BinaryMessage& pt_string, std::string& snap_path) { @@ -1554,12 +1575,6 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string, LOG4CXX_AUTO_TRACE(logger_); 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) { uint32_t app_id_for_sending = GetAppIdForSending(); @@ -1569,6 +1584,12 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string, } } else { + std::string policy_snapshot_full_path; + if (!SaveSnapshot(pt_string, policy_snapshot_full_path)) { + LOG4CXX_ERROR(logger_, "Snapshot processing skipped."); + return; + } + MessageHelper::SendPolicyUpdate( policy_snapshot_full_path, TimeoutExchangeSec(), @@ -1922,6 +1943,8 @@ void PolicyHandler::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(listeners_lock_); + PopAppIdFromPTUQueue(); + std::for_each( listeners_.begin(), listeners_.end(), @@ -2373,6 +2396,16 @@ 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) { + LOG4CXX_AUTO_TRACE(logger_); + if (policy_id == last_registered_policy_app_id_) { + return; + } + last_registered_policy_app_id_ = policy_id; + PushAppIdToPTUQueue(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 1e9f4d51b3..8ac85b53b4 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -418,6 +418,14 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; /** + * @brief Notify that new application 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. @@ -701,6 +709,12 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { const std::string& hmi_level) = 0; /** + * @brief OnPTUTimeOut the callback which is performed when PTU timeout + * occurred + */ + virtual void OnPTUTimeOut() = 0; + + /** * Gets all allowed module types * @param app_id unique identifier of application * @param list of allowed module types 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 935233e92d..16265ed7cc 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 applications count ready for PTU + * @param new_app_count new applications count for PTU + */ + virtual void UpdatePTUReadyAppsCount(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_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index 5b8245f6a4..192244bb09 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -128,7 +128,8 @@ class PolicyListener { virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; /** - * @brief OnPTUTimeOut the callback which signals if PTU timeout occured + * @brief OnPTUTimeOut the callback which is performed when PTU timeout + * occurred */ virtual void OnPTUTimeOut() = 0; 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 52923a53e2..a2d3a0ce70 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 applications count ready for PTU + * @param new_app_count new applications count for PTU + */ + virtual void UpdatePTUReadyAppsCount(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 a9cb70354a..6ac5ff5327 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 @@ -221,6 +221,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)); @@ -324,6 +326,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { void(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level)); + MOCK_METHOD0(OnPTUTimeOut, void()); MOCK_CONST_METHOD2(GetModuleTypes, bool(const std::string& policy_app_id, std::vector<std::string>* modules)); 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 5adb982410..3aaa62abf7 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 @@ -214,6 +214,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(UpdatePTUReadyAppsCount, 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 a76d61dfe4..bf9cce180c 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 @@ -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(UpdatePTUReadyAppsCount, 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 57499131f9..bf23429106 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 @@ -608,6 +608,8 @@ class PolicyManagerImpl : public PolicyManager { */ void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; + void UpdatePTUReadyAppsCount(const uint32_t new_app_count) OVERRIDE; + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id @@ -1080,6 +1082,11 @@ class PolicyManagerImpl : public PolicyManager { policy_table::PolicyTableType type) const; /** + * @brief Check that new applications for PTU were registered + */ + bool HasApplicationForPTU() const; + + /** * @brief Get resulting RPCs permissions for application which started on * specific device * @param device_id Device id @@ -1294,6 +1301,11 @@ class PolicyManagerImpl : public PolicyManager { uint32_t retry_sequence_index_; /** + * @brief Applications pending count ready for PTU + */ + uint32_t applications_pending_ptu_count_; + + /** * @brief Lock for guarding retry sequence */ mutable sync_primitives::Lock retry_sequence_lock_; @@ -1335,6 +1347,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/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h index 9426a26fb8..018bab7f99 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,12 @@ class UpdateStatusManager { void OnUpdateTimeoutOccurs(); /** + * @brief Update status for next in queue application + * after previous update been has finished + */ + void OnUpdateForNextInQueue(); + + /** * @brief Update status handler for valid PTU receiving */ void OnValidUpdateReceived(); @@ -222,6 +228,7 @@ class UpdateStatusManager { 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_; class UpdateThreadDelegate : public threads::ThreadDelegate { 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 cd2bd4c2d4..81b3206093 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) + , applications_pending_ptu_count_(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) + , applications_pending_ptu_count_(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) { @@ -543,6 +547,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(); @@ -551,7 +556,9 @@ void PolicyManagerImpl::OnPTUFinished(const PtProcessingResult ptu_result) { update_status_manager_.OnValidUpdateReceived(); - if (PtProcessingResult::kNewPtRequired == ptu_result) { + if (HasApplicationForPTU()) { + update_status_manager_.OnExistedApplicationAdded(true); + } else if (PtProcessingResult::kNewPtRequired == ptu_result) { LOG4CXX_DEBUG(logger_, "New PTU interation is required"); ForcePTExchange(); return; @@ -713,7 +720,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()); } else { @@ -773,6 +780,10 @@ void PolicyManagerImpl::OnAppsSearchCompleted(const bool trigger_ptu) { } } +void PolicyManagerImpl::UpdatePTUReadyAppsCount(const uint32_t new_app_count) { + applications_pending_ptu_count_ = new_app_count; +} + const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes( const transport_manager::DeviceHandle& device_handle, const std::string policy_app_id) const { @@ -1384,6 +1395,12 @@ void PolicyManagerImpl::RetrySequenceFailed() { listener_->OnPTUFinished(false); ResetRetrySequence(ResetRetryCountType::kResetWithStatusUpdate); + + ptu_requested_ = false; + if (HasApplicationForPTU()) { + update_status_manager_.OnExistedApplicationAdded(true); + StartPTExchange(); + } } void PolicyManagerImpl::ResetTimeout() { @@ -1647,6 +1664,10 @@ bool PolicyManagerImpl::IsPTValid( return true; } +bool PolicyManagerImpl::HasApplicationForPTU() const { + return applications_pending_ptu_count_ > 0; +} + const PolicySettings& PolicyManagerImpl::get_settings() const { DCHECK(settings_); return *settings_; @@ -2094,7 +2115,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); } @@ -2201,7 +2224,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 f605a51a98..826cca5a2e 100644 --- a/src/components/policy/policy_external/src/status.cc +++ b/src/components/policy/policy_external/src/status.cc @@ -67,9 +67,6 @@ void policy::UpdateNeededStatus::ProcessEvent( case kOnResetPolicyTableNoUpdate: manager->SetNextStatus(std::make_shared<UpToDateStatus>()); break; - case kOnNewAppRegistered: - manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); - break; case kPendingUpdate: manager->SetNextStatus(std::make_shared<UpdatePendingStatus>()); break; @@ -122,9 +119,6 @@ void policy::UpdatingStatus::ProcessEvent(policy::UpdateStatusManager* manager, case kOnResetPolicyTableNoUpdate: manager->SetNextStatus(std::make_shared<UpToDateStatus>()); break; - case kOnNewAppRegistered: - manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>()); - break; case kOnWrongUpdateReceived: case kOnUpdateTimeout: manager->SetNextStatus(std::make_shared<UpdateNeededStatus>()); 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 cfbd2fe32b..d34d1b7817 100644 --- a/src/components/policy/policy_external/src/update_status_manager.cc +++ b/src/components/policy/policy_external/src/update_status_manager.cc @@ -152,7 +152,12 @@ void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) { } LOG4CXX_DEBUG(logger_, "Application registered from consented device"); app_registered_from_non_consented_device_ = false; - ProcessEvent(kOnNewAppRegistered); + if (kOnResetRetrySequence == last_processed_event_) { + current_status_.reset(new UpToDateStatus()); + ProcessEvent(kScheduleUpdate); + } else { + ProcessEvent(kOnNewAppRegistered); + } } void UpdateStatusManager::OnDeviceConsented() { 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 a1a39ff80b..730346cc19 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 @@ -624,6 +624,8 @@ class PolicyManagerImpl : public PolicyManager { */ void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; + void UpdatePTUReadyAppsCount(const uint32_t new_app_count) OVERRIDE; + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id @@ -1032,6 +1034,11 @@ class PolicyManagerImpl : public PolicyManager { */ void OnPTUIterationTimeout(); + /** + * @brief Check that new applications for PTU were registered + */ + bool HasApplicationForPTU() const; + private: /** * @brief Get resulting RPCs permissions for application which started on @@ -1133,6 +1140,11 @@ class PolicyManagerImpl : public PolicyManager { uint32_t retry_sequence_index_; /** + * @brief Applications pending count ready for PTU + */ + uint32_t applications_pending_ptu_count_; + + /** * @brief Lock for guarding retry sequence */ sync_primitives::Lock retry_sequence_lock_; @@ -1181,6 +1193,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_policy_app_id_; + typedef std::list<std::pair<std::string, AppPoliciesValueType> > PendingAppPolicyActionsList; 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 94c1009086..b2c7e61f98 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) + , applications_pending_ptu_count_(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_policy_app_id_(std::string()) {} 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(); @@ -622,7 +625,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; } @@ -692,7 +695,8 @@ 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(); } } @@ -703,9 +707,18 @@ void PolicyManagerImpl::OnLocalAppAdded() { StartPTExchange(); } +void PolicyManagerImpl::UpdatePTUReadyAppsCount(const uint32_t new_app_count) { + LOG4CXX_AUTO_TRACE(logger_); + applications_pending_ptu_count_ = new_app_count; +} + void PolicyManagerImpl::OnAppRegisteredOnMobile( const std::string& device_id, const std::string& application_id) { - StartPTExchange(); + if (application_id != last_registered_policy_app_id_) { + StartPTExchange(); + last_registered_policy_app_id_ = application_id; + } + SendNotificationOnPermissionsUpdated(device_id, application_id); } @@ -1271,6 +1284,8 @@ void PolicyManagerImpl::IncrementIgnitionCycles() { std::string PolicyManagerImpl::ForcePTExchange() { update_status_manager_.ScheduleUpdate(); + + ptu_requested_ = false; StartPTExchange(); return update_status_manager_.StringifiedUpdateStatus(); } @@ -1336,6 +1351,7 @@ void PolicyManagerImpl::ResetRetrySequence( LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(retry_sequence_lock_); retry_sequence_index_ = 0; + ptu_requested_ = false; if (ResetRetryCountType::kResetWithStatusUpdate == reset_type) { update_status_manager_.OnResetRetrySequence(); } @@ -1512,7 +1528,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>(); } @@ -1644,6 +1662,10 @@ void PolicyManagerImpl::OnPTUIterationTimeout() { if (timer_retry_sequence_.is_running()) { timer_retry_sequence_.Stop(); } + + if (HasApplicationForPTU()) { + StartPTExchange(); + } return; } @@ -1662,6 +1684,10 @@ void PolicyManagerImpl::OnPTUIterationTimeout() { timer_retry_sequence_.Start(timeout_msec, timer::kPeriodic); } +bool PolicyManagerImpl::HasApplicationForPTU() const { + return applications_pending_ptu_count_ > 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 29d1bbf6b7..c870658622 100644 --- a/src/components/policy/policy_regular/src/status.cc +++ b/src/components/policy/policy_regular/src/status.cc @@ -71,7 +71,6 @@ void policy::UpdateNeededStatus::ProcessEvent( manager->SetNextStatus(std::make_shared<UpdatePendingStatus>()); 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 aa8d8cb3a2..1ba3d0f394 100644 --- a/src/components/policy/policy_regular/src/update_status_manager.cc +++ b/src/components/policy/policy_regular/src/update_status_manager.cc @@ -121,7 +121,12 @@ void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) { return; } app_registered_from_non_consented_device_ = false; - ProcessEvent(kOnNewAppRegistered); + if (kOnResetRetrySequence == last_processed_event_) { + current_status_.reset(new UpToDateStatus()); + ProcessEvent(kScheduleUpdate); + } else { + ProcessEvent(kOnNewAppRegistered); + } } void UpdateStatusManager::OnDeviceConsented() { |