summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2020-01-14 15:09:56 -0500
committerGitHub <noreply@github.com>2020-01-14 15:09:56 -0500
commit5f86dabef5686bdbaf48993be6e82edab0097b41 (patch)
tree35620334d7e57bab8321c56d080b4e3aa4aeddd9
parent72a7fc591b8b86608e6d3cbf64343ce8e45b59a4 (diff)
parent7d5222c6ca6e483113b51eae3332d9e94ec5444a (diff)
downloadsdl_core-5f86dabef5686bdbaf48993be6e82edab0097b41.tar.gz
Merge pull request #3203 from smartdevicelink/fix/BC.PolicyUpdate_twice
Fix BC.PolicyUpdate double sending
-rw-r--r--src/components/policy/policy_external/include/policy/status.h33
-rw-r--r--src/components/policy/policy_external/include/policy/update_status_manager.h6
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc4
-rw-r--r--src/components/policy/policy_external/src/status.cc32
-rw-r--r--src/components/policy/policy_external/src/update_status_manager.cc14
5 files changed, 87 insertions, 2 deletions
diff --git a/src/components/policy/policy_external/include/policy/status.h b/src/components/policy/policy_external/include/policy/status.h
index 336d59e869..f51888c853 100644
--- a/src/components/policy/policy_external/include/policy/status.h
+++ b/src/components/policy/policy_external/include/policy/status.h
@@ -52,6 +52,7 @@ enum UpdateEvent {
kOnResetPolicyTableRequireUpdate,
kOnResetPolicyTableNoUpdate,
kScheduleUpdate,
+ kPendingUpdate,
kScheduleManualUpdate,
kOnResetRetrySequence,
kNoEvent
@@ -162,6 +163,38 @@ class UpdateNeededStatus : public Status {
};
/**
+ * @brief The UpdatePendingStatus class represents cases when SDL knows that an
+ * update is required and but before the snapshot is sent to the HMI
+ */
+class UpdatePendingStatus : public Status {
+ public:
+ /**
+ * @brief Constructor
+ */
+ UpdatePendingStatus();
+
+ /**
+ * @brief Process event by setting next status in case event can affect
+ * current status or ignores the event
+ * @param manager Status manager pointer
+ * @param event Event which needs to be processed
+ */
+ void ProcessEvent(UpdateStatusManager* manager, UpdateEvent event) OVERRIDE;
+
+ /**
+ * @brief Check whether update is required in terms of status
+ * @return True if update is required, otherwise - false
+ */
+ bool IsUpdateRequired() const OVERRIDE;
+
+ /**
+ * @brief Check whether update is pending in terms of status
+ * @return True if update is pending, otherwise - false
+ */
+ bool IsUpdatePending() const OVERRIDE;
+};
+
+/**
* @brief The UpdatingStatus class represents 'updating' status
*/
class UpdatingStatus : public Status {
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 9c0e29407e..c5738b3272 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
@@ -150,6 +150,12 @@ class UpdateStatusManager {
void ScheduleUpdate();
/**
+ * @brief PendingUpdate will change state from Update_Needed
+ * to Update_Pending
+ */
+ void PendingUpdate();
+
+ /**
* @brief ScheduleUpdate allows to schedule next update.
* It will change state to Update_Needed, that's is
* and will not send any notifications about updating to HMI
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 6868b9060c..152a94b963 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -745,6 +745,7 @@ void PolicyManagerImpl::StartPTExchange() {
if (listener_ && listener_->CanUpdate()) {
LOG4CXX_INFO(logger_, "Listener CanUpdate");
if (update_status_manager_.IsUpdateRequired()) {
+ update_status_manager_.PendingUpdate();
LOG4CXX_INFO(logger_, "IsUpdateRequired");
RequestPTUpdate();
}
@@ -1975,7 +1976,8 @@ void PolicyManagerImpl::OnUpdateStarted() {
uint32_t update_timeout = TimeoutExchangeMSec();
LOG4CXX_DEBUG(logger_,
"Update timeout will be set to (milisec): " << update_timeout);
- send_on_update_sent_out_ = !update_status_manager_.IsUpdatePending();
+ send_on_update_sent_out_ =
+ policy::kUpdating != update_status_manager_.StringifiedUpdateStatus();
if (send_on_update_sent_out_) {
update_status_manager_.OnUpdateSentOut(update_timeout);
diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc
index 3d1cae3eba..7162410731 100644
--- a/src/components/policy/policy_external/src/status.cc
+++ b/src/components/policy/policy_external/src/status.cc
@@ -67,6 +67,9 @@ void policy::UpdateNeededStatus::ProcessEvent(
case kOnResetPolicyTableNoUpdate:
manager->SetNextStatus(std::make_shared<UpToDateStatus>());
break;
+ case kPendingUpdate:
+ manager->SetNextStatus(std::make_shared<UpdatePendingStatus>());
+ break;
default:
break;
}
@@ -76,6 +79,35 @@ bool policy::UpdateNeededStatus::IsUpdateRequired() const {
return true;
}
+policy::UpdatePendingStatus::UpdatePendingStatus()
+ : Status(kUpdateNeeded, policy::PolicyTableStatus::StatusUpdatePending) {}
+
+void policy::UpdatePendingStatus::ProcessEvent(
+ policy::UpdateStatusManager* manager, policy::UpdateEvent event) {
+ switch (event) {
+ case kOnUpdateSentOut:
+ manager->SetNextStatus(std::make_shared<UpdatingStatus>());
+ break;
+ case kOnResetPolicyTableRequireUpdate:
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
+ manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
+ break;
+ case kOnResetPolicyTableNoUpdate:
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
+ break;
+ default:
+ break;
+ }
+}
+
+bool policy::UpdatePendingStatus::IsUpdatePending() const {
+ return true;
+}
+
+bool policy::UpdatePendingStatus::IsUpdateRequired() const {
+ return true;
+}
+
policy::UpdatingStatus::UpdatingStatus()
: Status(kUpdating, policy::PolicyTableStatus::StatusUpdatePending) {}
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 050908f3a0..bf20f9dd55 100644
--- a/src/components/policy/policy_external/src/update_status_manager.cc
+++ b/src/components/policy/policy_external/src/update_status_manager.cc
@@ -61,6 +61,7 @@ UpdateStatusManager::~UpdateStatusManager() {
}
void UpdateStatusManager::ProcessEvent(UpdateEvent event) {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(status_lock_);
current_status_->ProcessEvent(this, event);
last_processed_event_ = event;
@@ -164,10 +165,17 @@ bool UpdateStatusManager::IsUpdatePending() const {
}
void UpdateStatusManager::ScheduleUpdate() {
+ LOG4CXX_AUTO_TRACE(logger_);
ProcessEvent(kScheduleUpdate);
}
+void UpdateStatusManager::PendingUpdate() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ ProcessEvent(kPendingUpdate);
+}
+
void UpdateStatusManager::ScheduleManualUpdate() {
+ LOG4CXX_AUTO_TRACE(logger_);
ProcessEvent(kScheduleManualUpdate);
}
@@ -202,7 +210,11 @@ void UpdateStatusManager::DoTransition() {
current_status_ = next_status_;
next_status_.reset();
- if (last_processed_event_ != kScheduleManualUpdate) {
+ const bool is_update_pending =
+ (policy::kUpdateNeeded == current_status_->get_status_string() &&
+ policy::StatusUpdatePending == current_status_->get_status());
+
+ if (last_processed_event_ != kScheduleManualUpdate && !is_update_pending) {
listener_->OnUpdateStatusChanged(current_status_->get_status_string());
}