summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_external
diff options
context:
space:
mode:
authorYevhenii Dementieiev (GitHub) <57259850+ydementieiev@users.noreply.github.com>2020-02-28 22:03:44 +0200
committerGitHub <noreply@github.com>2020-02-28 15:03:44 -0500
commitce12181630c0923cf821bfa314d46be02e5380bc (patch)
tree5116ed78739b31d6bf8b853a0557df92915e133c /src/components/policy/policy_external
parentdd39efa5cf98baba8cf189d2992842f45cef64dc (diff)
downloadsdl_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>
Diffstat (limited to 'src/components/policy/policy_external')
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h17
-rw-r--r--src/components/policy/policy_external/include/policy/update_status_manager.h7
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc33
-rw-r--r--src/components/policy/policy_external/src/status.cc6
-rw-r--r--src/components/policy/policy_external/src/update_status_manager.cc7
5 files changed, 59 insertions, 11 deletions
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() {