summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsniukalov <sniukalov@luxoft.com>2019-05-30 09:46:44 +0300
committermked-luxoft <mked@luxoft.com>2019-08-29 17:56:13 +0300
commitf3ce96ae1246c65dbf4e4ae536e5503107365c0e (patch)
tree81360cd318de1c479f5c7c76e112dcc6f539996f
parentf52a562c71690dab5d2853e44459b89b60f2c08a (diff)
downloadsdl_core-f3ce96ae1246c65dbf4e4ae536e5503107365c0e.tar.gz
Added sending error on PTU retries exceed allowed count
-rw-r--r--src/components/application_manager/include/application_manager/application_manager_impl.h3
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h11
-rw-r--r--src/components/application_manager/include/application_manager/policies/policy_handler.h5
-rw-r--r--src/components/application_manager/include/application_manager/policies/ptu_retry_handler.h66
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc15
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc5
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc35
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc31
-rw-r--r--src/components/include/application_manager/policies/policy_handler_interface.h7
-rw-r--r--src/components/include/policy/policy_external/policy/policy_listener.h4
-rw-r--r--src/components/include/policy/policy_external/policy/policy_manager.h7
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_listener.h6
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_manager.h9
-rw-r--r--src/components/include/security_manager/security_manager_listener.h2
-rw-r--r--src/components/include/test/application_manager/policies/mock_policy_handler_interface.h1
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_listener.h2
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_manager.h7
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h33
-rw-r--r--src/components/policy/policy_external/include/policy/policy_types.h2
-rw-r--r--src/components/policy/policy_external/include/policy/ptu_retry_handler.h57
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc94
-rw-r--r--src/components/policy/policy_external/src/status.cc4
-rw-r--r--src/components/policy/policy_external/src/update_status_manager.cc9
-rw-r--r--src/components/policy/policy_external/test/update_status_manager_test.cc32
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h6
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_types.h4
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc29
-rw-r--r--src/components/policy/policy_regular/src/status.cc4
-rw-r--r--src/components/protocol_handler/docs/assets/PTU_for_EXTERNAL_PROPRIETARY.pngbin92488 -> 95754 bytes
-rw-r--r--src/components/protocol_handler/include/protocol_handler/handshake_handler.h2
-rw-r--r--src/components/protocol_handler/src/handshake_handler.cc4
-rw-r--r--src/components/security_manager/src/security_manager_impl.cc18
32 files changed, 462 insertions, 52 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 7071610acb..3be9f56a3f 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
@@ -585,8 +585,7 @@ class ApplicationManagerImpl
utils::Optional<hmi_apis::Common_ServiceUpdateReason::eType>
service_update_reason) FINAL;
- void OnPTUFailed() FINAL {}
-
+ bool OnPTUFailed() FINAL;
/*
* @brief Starts audio pass thru thread
*
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h
index 7b390d7adf..480694e18d 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -90,6 +90,17 @@ class MessageHelper {
hmi_apis::FunctionID::eType function_id);
/**
+ * @brief CreateOnSystemRequestNotificationToMobile creates mobile
+ * OnSystemRequestNotification
+ * @param policy_data pt snapshot data
+ * @param connection_key connection key of application
+ * @return OnSystemRequest notification smart object
+ */
+ static smart_objects::SmartObjectSPtr
+ CreateOnSystemRequestNotificationToMobile(
+ const std::vector<uint8_t>& policy_data, const uint32_t connection_key);
+
+ /**
* @brief ServiceStatusUpdateNotificationBuilder small utility class used for
* more flexible construction of OnServiceUpdateNotification
*/
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 39026b3420..d2dcc109f2 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
@@ -103,8 +103,11 @@ class PolicyHandler : public PolicyHandlerInterface,
void OnSnapshotCreated(const BinaryMessage& pt_string,
const std::vector<int>& retry_delay_seconds,
uint32_t timeout_exchange) OVERRIDE;
+
+ PTURetryHandler& ptu_retry_handler() const OVERRIDE;
#else // EXTERNAL_PROPRIETARY_MODE
- void OnSnapshotCreated(const BinaryMessage& pt_string) OVERRIDE;
+ void OnSnapshotCreated(const BinaryMessage& pt_string,
+ const PTUIterationType iteration_type) OVERRIDE;
#endif // EXTERNAL_PROPRIETARY_MODE
virtual bool GetPriority(const std::string& policy_app_id,
std::string* priority) const OVERRIDE;
diff --git a/src/components/application_manager/include/application_manager/policies/ptu_retry_handler.h b/src/components/application_manager/include/application_manager/policies/ptu_retry_handler.h
new file mode 100644
index 0000000000..8d52641daf
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/policies/ptu_retry_handler.h
@@ -0,0 +1,66 @@
+/*
+ Copyright (c) 2019, Ford Motor Company
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
+
+namespace policy {
+
+class PTURetryHandler {
+ public:
+ /**
+ * @brief Check whether allowed retry sequence count is exceeded
+ * @return bool value - true is allowed count is exceeded, otherwise - false
+ */
+ virtual bool IsAllowedRetryCountExceeded() const = 0;
+
+ /**
+ * @brief Begins new retry sequence
+ */
+ virtual void BeginRetrySequence() = 0;
+ /**
+ * @brief Start timer waiting for OnSystemRequest from HMI.
+ */
+ virtual void StartWaitingPTURetry() = 0;
+
+ /**
+ * @brief Stop timer waiting for git OnSystemRequest from HMI.
+ */
+ virtual void StopWaitingPTURetry() = 0;
+
+ /**
+ * @brief Handle retry sequence failure
+ */
+ virtual void RetrySequenceFailed() = 0;
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc
index a9670681b2..6d95febe71 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc
@@ -37,6 +37,10 @@
#include "sdl_rpc_plugin/commands/hmi/on_system_request_notification.h"
#include "utils/macro.h"
+#ifdef EXTERNAL_PROPRIETARY_MODE
+#include "policy/ptu_retry_handler.h"
+#endif // EXTERNAL_PROPRIETARY_MODE
+
using policy::PolicyHandlerInterface;
namespace sdl_rpc_plugin {
@@ -116,6 +120,17 @@ void OnSystemRequestNotification::Run() {
"Sending request with application id " << app->policy_app_id());
params[strings::connection_key] = app->app_id();
+
+#ifdef EXTERNAL_PROPRIETARY_MODE
+ using namespace rpc::policy_table_interface_base;
+ const auto request_type =
+ static_cast<rpc::policy_table_interface_base::RequestType>(
+ (*message_)[strings::msg_params][strings::request_type].asUInt());
+
+ if (RequestType::RT_PROPRIETARY == request_type) {
+ policy_handler_.ptu_retry_handler().OnSystemRequestReceived();
+ }
+#endif
SendNotificationToMobile(message_);
}
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index 6f5c5a82e3..1b8fd0187e 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -2167,6 +2167,11 @@ bool ApplicationManagerImpl::OnHandshakeDone(
return false;
}
+bool ApplicationManagerImpl::OnPTUFailed() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return false;
+}
+
bool ApplicationManagerImpl::OnGetSystemTimeFailed() {
LOG4CXX_AUTO_TRACE(logger_);
return false;
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index c90711b675..050e672697 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -2465,31 +2465,54 @@ bool MessageHelper::SendUnsubscribedWayPoints(ApplicationManager& app_mngr) {
return app_mngr.GetRPCService().ManageHMICommand(result);
}
+smart_objects::SmartObjectSPtr
+MessageHelper::CreateOnSystemRequestNotificationToMobile(
+ const std::vector<uint8_t>& policy_data, const uint32_t app_id) {
+ auto notification =
+ CreateNotification(mobile_apis::FunctionID::OnSystemRequestID, app_id);
+
+ (*notification)[strings::params][strings::binary_data] =
+ smart_objects::SmartObject(policy_data);
+
+#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE)
+ (*notification)[strings::msg_params][strings::request_type] =
+ mobile_apis::RequestType::PROPRIETARY;
+#else
+ (*notification)[strings::msg_params][strings::request_type] =
+ mobile_apis::RequestType::HTTP;
+#endif // PROPRIETARY || EXTERNAL_PROPRIETARY_MODE
+
+ return notification;
+}
+
void MessageHelper::SendPolicySnapshotNotification(
uint32_t connection_key,
const std::vector<uint8_t>& policy_data,
const std::string& url,
ApplicationManager& app_mngr) {
- smart_objects::SmartObject content(smart_objects::SmartType_Map);
+ auto notification =
+ CreateOnSystemRequestNotificationToMobile(policy_data, connection_key);
if (!url.empty()) {
- content[strings::msg_params][strings::url] =
+ (*notification)[strings::msg_params][strings::url] =
url; // Doesn't work with mobile_notification::syncp_url ("URL")
} else {
LOG4CXX_WARN(logger_, "No service URLs");
}
- content[strings::params][strings::binary_data] =
+ (*notification)[strings::params][strings::binary_data] =
smart_objects::SmartObject(policy_data);
#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE)
- content[strings::msg_params][strings::request_type] =
+ (*notification)[strings::msg_params][strings::request_type] =
mobile_apis::RequestType::PROPRIETARY;
#else
- content[strings::msg_params][strings::request_type] =
+ (*notification)[strings::msg_params][strings::request_type] =
mobile_apis::RequestType::HTTP;
#endif // PROPRIETARY || EXTERNAL_PROPRIETARY_MODE
- SendSystemRequestNotification(connection_key, content, app_mngr);
+ PrintSmartObject(*notification);
+ app_mngr.GetRPCService().ManageMobileCommand(notification,
+ commands::Command::SOURCE_SDL);
}
void MessageHelper::SendSystemRequestNotification(
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 7085d7a86c..b5f0371555 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -58,6 +58,9 @@
#include "policy/policy_manager.h"
#include "utils/helpers.h"
+#ifdef EXTERNAL_PROPRIETARY_MODE
+#include "policy/ptu_retry_handler.h"
+#endif // EXTERNAL_PROPRIETARY_MODE
namespace policy {
@@ -443,6 +446,11 @@ uint32_t PolicyHandler::GetAppIdForSending() const {
}
#ifdef EXTERNAL_PROPRIETARY_MODE
+PTURetryHandler& PolicyHandler::ptu_retry_handler() const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return *policy_manager_;
+}
+
void PolicyHandler::OnAppPermissionConsent(
const uint32_t connection_key,
const PermissionConsent& permissions,
@@ -1502,7 +1510,8 @@ void PolicyHandler::OnSnapshotCreated(
}
}
#else // EXTERNAL_PROPRIETARY_MODE
-void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string) {
+void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string,
+ const PTUIterationType iteration_type) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
#ifdef PROPRIETARY_MODE
@@ -1511,10 +1520,20 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string) {
LOG4CXX_ERROR(logger_, "Snapshot processing skipped.");
return;
}
- MessageHelper::SendPolicyUpdate(policy_snapshot_full_path,
- TimeoutExchangeSec(),
- policy_manager_->RetrySequenceDelaysSeconds(),
- application_manager_);
+
+ if (PTUIterationType::RetryIteration == iteration_type) {
+ auto on_system_request_notification =
+ MessageHelper::CreateOnSystemRequestNotificationToMobile(
+ pt_string, GetAppIdForSending());
+ application_manager_.GetRPCService().ManageMobileCommand(
+ on_system_request_notification, commands::Command::SOURCE_SDL);
+ } else {
+ MessageHelper::SendPolicyUpdate(
+ policy_snapshot_full_path,
+ TimeoutExchangeSec(),
+ policy_manager_->RetrySequenceDelaysSeconds(),
+ application_manager_);
+ }
#else // PROPRIETARY_MODE
LOG4CXX_ERROR(logger_, "HTTP policy");
EndpointUrls urls;
@@ -1634,6 +1653,7 @@ uint32_t PolicyHandler::TimeoutExchangeMSec() const {
}
void PolicyHandler::OnExceededTimeout() {
+ LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
std::for_each(listeners_.begin(),
@@ -1831,6 +1851,7 @@ void PolicyHandler::ProcessCertDecryptFailed() {
std::bind2nd(std::mem_fn(&PolicyHandlerObserver::OnCertDecryptFinished),
false));
}
+
#else // EXTERNAL_PROPRIETARY_MODE
void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) {
LOG4CXX_AUTO_TRACE(logger_);
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 8e450edd49..ae18779c03 100644
--- a/src/components/include/application_manager/policies/policy_handler_interface.h
+++ b/src/components/include/application_manager/policies/policy_handler_interface.h
@@ -59,6 +59,8 @@ typedef std::shared_ptr<utils::Callable> StatusNotifier;
typedef std::shared_ptr<PolicyEncryptionFlagGetterInterface>
PolicyEncryptionFlagGetterInterfaceSPtr;
+class PTURetryHandler;
+
class PolicyHandlerInterface {
public:
virtual ~PolicyHandlerInterface() {}
@@ -87,8 +89,11 @@ class PolicyHandlerInterface {
virtual void OnSnapshotCreated(const BinaryMessage& pt_string,
const std::vector<int>& retry_delay_seconds,
uint32_t timeout_exchange) = 0;
+
+ virtual PTURetryHandler& ptu_retry_handler() const = 0;
#else // EXTERNAL_PROPRIETARY_MODE
- virtual void OnSnapshotCreated(const BinaryMessage& pt_string) = 0;
+ virtual void OnSnapshotCreated(const BinaryMessage& pt_string,
+ const PTUIterationType iteration_type) = 0;
#endif // EXTERNAL_PROPRIETARY_MODE
virtual bool GetPriority(const std::string& policy_app_id,
diff --git a/src/components/include/policy/policy_external/policy/policy_listener.h b/src/components/include/policy/policy_external/policy/policy_listener.h
index 8203f5c9b6..8220d05584 100644
--- a/src/components/include/policy/policy_external/policy/policy_listener.h
+++ b/src/components/include/policy/policy_external/policy/policy_listener.h
@@ -42,6 +42,8 @@ namespace policy {
namespace custom_str = utils::custom_string;
+class PTURetryHandler;
+
class PolicyListener {
public:
virtual ~PolicyListener() {}
@@ -187,6 +189,8 @@ class PolicyListener {
* LockScreenDismissal
*/
virtual void OnLockScreenDismissalStateChanged() = 0;
+
+ virtual PTURetryHandler& ptu_retry_handler() const = 0;
};
} // namespace policy
#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_EXTERNAL_POLICY_POLICY_LISTENER_H_
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 1242c7a460..da1a99fcde 100644
--- a/src/components/include/policy/policy_external/policy/policy_manager.h
+++ b/src/components/include/policy/policy_external/policy/policy_manager.h
@@ -44,6 +44,7 @@
#include "policy/policy_listener.h"
#include "policy/policy_table/types.h"
#include "policy/policy_types.h"
+#include "policy/ptu_retry_handler.h"
#include "policy/usage_statistics/statistics_manager.h"
namespace policy {
@@ -51,7 +52,8 @@ class PolicySettings;
typedef std::shared_ptr<utils::Callable> StatusNotifier;
class PolicyManager : public usage_statistics::StatisticsManager,
- public PolicyEncryptionFlagGetterInterface {
+ public PolicyEncryptionFlagGetterInterface,
+ public PTURetryHandler {
public:
/**
* @brief The NotificationMode enum defines whether application will be
@@ -206,8 +208,9 @@ class PolicyManager : public usage_statistics::StatisticsManager,
/**
* @brief Resets retry sequence
+ * @param reset_type - reset retry count with sending OnStatusUpdate or not
*/
- virtual void ResetRetrySequence() = 0;
+ virtual void ResetRetrySequence(const ResetRetryCountType reset_type) = 0;
/**
* @brief Gets timeout to wait before next retry updating PT
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 3e23df9710..bbe220060e 100644
--- a/src/components/include/policy/policy_regular/policy/policy_listener.h
+++ b/src/components/include/policy/policy_regular/policy/policy_listener.h
@@ -79,11 +79,13 @@ class PolicyListener {
*
* @param pt_string the snapshot
*
- * @param retry_seconds retry sequence timeouts.
+ * @param iteration_type flag indicating whether PTU was caused by retry
+ * sequence.
*
* @param timeout_exceed timeout.
*/
- virtual void OnSnapshotCreated(const BinaryMessage& pt_string) = 0;
+ virtual void OnSnapshotCreated(const BinaryMessage& pt_string,
+ const PTUIterationType iteration_type) = 0;
/**
* @brief Make appropriate changes for related applications permissions and
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 65f4cb69ff..27ae18eca8 100644
--- a/src/components/include/policy/policy_regular/policy/policy_manager.h
+++ b/src/components/include/policy/policy_regular/policy/policy_manager.h
@@ -117,7 +117,7 @@ class PolicyManager : public usage_statistics::StatisticsManager,
/**
* @brief PTU is needed, for this PTS has to be formed and sent.
*/
- virtual bool RequestPTUpdate() = 0;
+ virtual bool RequestPTUpdate(const PTUIterationType iteration_type) = 0;
/**
* @brief Check if specified RPC for specified application
@@ -202,6 +202,13 @@ class PolicyManager : public usage_statistics::StatisticsManager,
virtual std::string ForcePTExchangeAtUserRequest() = 0;
/**
+ * @brief Resets retry sequence
+ * @param send_event - if true corresponding event is sent to
+ * UpdateStatusManager
+ */
+ virtual void ResetRetrySequence(const ResetRetryCountType reset_type) = 0;
+
+ /**
* @brief Gets timeout to wait before next retry updating PT
* If timeout is less or equal to zero then the retry sequence is not need.
* @return timeout in seconds
diff --git a/src/components/include/security_manager/security_manager_listener.h b/src/components/include/security_manager/security_manager_listener.h
index f7148d3165..0648ed0a11 100644
--- a/src/components/include/security_manager/security_manager_listener.h
+++ b/src/components/include/security_manager/security_manager_listener.h
@@ -59,7 +59,7 @@ class SecurityManagerListener {
*/
virtual void OnCertificateUpdateRequired() = 0;
- virtual void OnPTUFailed() = 0;
+ virtual bool OnPTUFailed() = 0;
#ifdef EXTERNAL_PROPRIETARY_MODE
/**
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 f5b6f28825..c292272d4c 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
@@ -261,6 +261,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
#ifdef EXTERNAL_PROPRIETARY_MODE
MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo());
+ MOCK_METHOD0(IncrementRetryIndex, void());
#endif // EXTERNAL_PROPRIETARY_MODE
MOCK_METHOD1(Increment, void(usage_statistics::GlobalCounterId type));
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
index f65138e489..0faa6d6dea 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
@@ -113,6 +113,8 @@ class MockPolicyListener : public ::policy::PolicyListener {
const std::string& hmi_level));
MOCK_METHOD0(OnLockScreenDismissalStateChanged, void());
MOCK_METHOD1(OnCertDecryptFinished, void(bool));
+ MOCK_METHOD0(IncrementRetryIndex, void());
+ MOCK_CONST_METHOD0(IsAllowedPTURetriesExceeded, bool());
};
} // namespace policy_test
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 7c71643044..82edd959d2 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
@@ -102,7 +102,7 @@ class MockPolicyManager : public PolicyManager {
MOCK_METHOD0(IncrementIgnitionCycles, void());
MOCK_METHOD0(ForcePTExchange, std::string());
MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string());
- MOCK_METHOD0(ResetRetrySequence, void());
+ MOCK_METHOD1(ResetRetrySequence, void(const bool send_event));
MOCK_METHOD0(NextRetryTimeout, int());
MOCK_METHOD0(TimeoutExchangeMSec, uint32_t());
MOCK_METHOD0(RetrySequenceDelaysSeconds, const std::vector<int>());
@@ -291,6 +291,11 @@ class MockPolicyManager : public PolicyManager {
RequestType::State(const std::string& policy_app_id));
MOCK_CONST_METHOD1(GetAppRequestSubTypesState,
RequestSubType::State(const std::string& policy_app_id));
+ MOCK_METHOD0(IncrementPTURetryIndex, void());
+ MOCK_CONST_METHOD0(IsAllowedPTURetryCountExceeded, bool());
+ MOCK_CONST_METHOD0(IsAllowedRetryCountExceeded, bool());
+ MOCK_METHOD0(OnSystemRequestReceived, void());
+ MOCK_METHOD0(RetrySequenceFailed, void());
};
} // namespace policy_manager_test
} // namespace components
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 cb06a65e41..ed4d2f7a01 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
@@ -44,6 +44,7 @@
#include "policy/update_status_manager.h"
#include "policy/usage_statistics/statistics_manager.h"
#include "utils/lock.h"
+#include "utils/timer.h"
namespace policy_table = rpc::policy_table_interface_base;
@@ -220,8 +221,10 @@ class PolicyManagerImpl : public PolicyManager {
/**
* @brief Resets retry sequence
+ * @param send_event - if true corresponding event is sent to
+ * UpdateStatusManager
*/
- void ResetRetrySequence() OVERRIDE;
+ void ResetRetrySequence(const ResetRetryCountType reset_type) OVERRIDE;
/**
* @brief Gets timeout to wait before next retry updating PT
@@ -885,8 +888,25 @@ class PolicyManagerImpl : public PolicyManager {
void Add(const std::string& app_id,
usage_statistics::AppStopwatchId type,
int32_t timespan_seconds) OVERRIDE;
+
// Interface StatisticsManager (end)
+ /**
+ * @brief Check whether allowed retry sequence count is exceeded
+ * @return bool value - true is allowed count is exceeded, otherwise - false
+ */
+ bool IsAllowedRetryCountExceeded() const OVERRIDE;
+
+ /**
+ * @brief Finish PTU retry requence
+ */
+ void RetrySequenceFailed() OVERRIDE;
+
+ /**
+ * @brief Begins new retry sequence
+ */
+ void OnSystemRequestReceived() OVERRIDE;
+
protected:
/**
* @brief Parse policy table content and convert to PT object
@@ -898,6 +918,11 @@ class PolicyManagerImpl : public PolicyManager {
private:
/**
+ * @brief Increments PTU retry index for external flow
+ */
+ void IncrementRetryIndex();
+
+ /**
* @brief Checks if PT update should be started and schedules it if needed
*/
void CheckTriggers();
@@ -1303,6 +1328,12 @@ class PolicyManagerImpl : public PolicyManager {
* @brief Flag for notifying that invalid PTU should be triggered
*/
bool trigger_ptu_;
+
+ /**
+ * @brief Flag that indicates whether a PTU sequence (including retries) is in
+ * progress
+ */
+ bool is_ptu_in_progress_;
};
} // namespace policy
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 fcf6c33c1b..fe63ae3479 100644
--- a/src/components/policy/policy_external/include/policy/policy_types.h
+++ b/src/components/policy/policy_external/include/policy/policy_types.h
@@ -122,6 +122,8 @@ typedef std::vector<std::string> StringArray;
enum PermitResult { kRpcAllowed = 0, kRpcDisallowed, kRpcUserDisallowed };
+enum class ResetRetryCountType { kResetWithStatusUpdate = 0, kResetInternally };
+
/**
* @struct Stores result of check:
* if HMI Level was allowed for RPC to work in
diff --git a/src/components/policy/policy_external/include/policy/ptu_retry_handler.h b/src/components/policy/policy_external/include/policy/ptu_retry_handler.h
new file mode 100644
index 0000000000..79623124e3
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/ptu_retry_handler.h
@@ -0,0 +1,57 @@
+/*
+ Copyright (c) 2019, Ford Motor Company
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
+
+namespace policy {
+
+class PTURetryHandler {
+ public:
+ /**
+ * @brief Check whether allowed retry sequence count is exceeded
+ * @return bool value - true is allowed count is exceeded, otherwise - false
+ */
+ virtual bool IsAllowedRetryCountExceeded() const = 0;
+
+ /**
+ * @brief Begins new retry sequence
+ */
+ virtual void OnSystemRequestReceived() = 0;
+
+ /**
+ * @brief Handle OnSystemRequest from HMI timeout
+ */
+ virtual void RetrySequenceFailed() = 0;
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_PTU_RETRY_HANDLER_H_
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 255f6050a6..1b8c7a8c87 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -52,6 +52,8 @@
#include "policy/access_remote.h"
#include "policy/access_remote_impl.h"
+#include "policy/ptu_retry_handler.h"
+#include "utils/timer_task_impl.h"
__attribute__((visibility("default"))) policy::PolicyManager* CreateManager() {
return new policy::PolicyManagerImpl();
@@ -220,7 +222,8 @@ PolicyManagerImpl::PolicyManagerImpl()
, retry_sequence_timeout_(60)
, retry_sequence_index_(0)
, ignition_check(true)
- , retry_sequence_url_(0, 0, "") {}
+ , retry_sequence_url_(0, 0, "")
+ , is_ptu_in_progress_(false) {}
PolicyManagerImpl::PolicyManagerImpl(bool in_memory)
: PolicyManager()
@@ -234,7 +237,8 @@ PolicyManagerImpl::PolicyManagerImpl(bool in_memory)
, retry_sequence_url_(0, 0, "")
, wrong_ptu_update_received_(false)
, send_on_update_sent_out_(false)
- , trigger_ptu_(false) {}
+ , trigger_ptu_(false)
+ , is_ptu_in_progress_(false) {}
void PolicyManagerImpl::set_listener(PolicyListener* listener) {
listener_ = listener;
@@ -832,6 +836,9 @@ void PolicyManagerImpl::CheckPermissions(const PTString& device_id,
LOG4CXX_INFO(logger_,
"CheckPermissions for " << app_id << " and rpc " << rpc
<< " for " << hmi_level << " level.");
+
+ const std::string device_id = GetCurrentDeviceId(app_id);
+
Permissions rpc_permissions;
// Check, if there are calculated permission present in cache
@@ -1003,6 +1010,7 @@ policy_table::Strings PolicyManagerImpl::GetGroupsNames(
void PolicyManagerImpl::SendNotificationOnPermissionsUpdated(
const std::string& device_id, const std::string& application_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ const std::string device_id = GetCurrentDeviceId(application_id);
if (device_id.empty()) {
LOG4CXX_WARN(logger_,
"Couldn't find device info for application id "
@@ -1108,7 +1116,7 @@ bool PolicyManagerImpl::ReactOnUserDevConsentForApp(
}
if (permissions.requestTypeChanged || (!permissions.priority.empty())) {
- auto device_id = GetCurrentDeviceId(device_handle, app_id);
+ const auto& device_id = GetCurrentDeviceId(device_handle, app_id);
listener_->SendOnAppPermissionsChanged(permissions, device_id, app_id);
}
return result;
@@ -1287,6 +1295,36 @@ void PolicyManagerImpl::SetUserConsentForApp(
updated_app_group_permissons);
}
+bool PolicyManagerImpl::IsAllowedRetryCountExceeded() const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return retry_sequence_index_ > retry_sequence_seconds_.size();
+}
+
+void PolicyManagerImpl::IncrementRetryIndex() {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ ++retry_sequence_index_;
+ LOG4CXX_DEBUG(logger_,
+ "current retry_sequence_index_ is: " << retry_sequence_index_);
+}
+
+void PolicyManagerImpl::RetrySequenceFailed() {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ listener_->OnPTUFinished(false);
+ ResetRetrySequence(ResetRetryCountType::kResetWithStatusUpdate);
+}
+
+void PolicyManagerImpl::OnSystemRequestReceived() {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ if (is_ptu_in_progress_) {
+ IncrementRetryIndex();
+ } else {
+ is_ptu_in_progress_ = true;
+ }
+}
+
bool PolicyManagerImpl::GetDefaultHmi(const std::string& device_id,
const std::string& policy_app_id,
std::string* default_hmi) const {
@@ -1395,11 +1433,13 @@ void PolicyManagerImpl::GetPermissionsForApp(
}
bool allowed_by_default = false;
- if (cache_->IsDefaultPolicy(policy_app_id)) {
+ const auto device_consent = GetUserConsentForDevice(device_id);
+ if ((policy::kDeviceAllowed == device_consent) &&
+ cache_->IsDefaultPolicy(policy_app_id)) {
app_id_to_check = kDefaultId;
allowed_by_default = true;
} else if (cache_->IsPredataPolicy(policy_app_id) ||
- policy::kDeviceDisallowed == GetUserConsentForDevice(device_id)) {
+ policy::kDeviceAllowed != device_consent) {
app_id_to_check = kPreDataConsentId;
allowed_by_default = true;
}
@@ -1592,7 +1632,7 @@ void PolicyManagerImpl::UpdateAppConsentWithExternalConsent(
void PolicyManagerImpl::NotifySystem(
const std::string& device_id,
- const AppPoliciesValueType& app_policy) const {
+ const PolicyManagerImpl::AppPoliciesValueType& app_policy) const {
listener()->OnPendingPermissionChange(device_id, app_policy.first);
}
@@ -1767,12 +1807,14 @@ void PolicyManagerImpl::KmsChanged(int kilometers) {
const boost::optional<bool> PolicyManagerImpl::LockScreenDismissalEnabledState()
const {
+ LOG4CXX_AUTO_TRACE(logger_);
return cache_->LockScreenDismissalEnabledState();
}
const boost::optional<std::string>
PolicyManagerImpl::LockScreenDismissalWarningMessage(
const std::string& language) const {
+ LOG4CXX_AUTO_TRACE(logger_);
return cache_->LockScreenDismissalWarningMessage(language);
}
@@ -1801,10 +1843,11 @@ int PolicyManagerImpl::NextRetryTimeout() {
sync_primitives::AutoLock auto_lock(retry_sequence_lock_);
LOG4CXX_DEBUG(logger_, "Index: " << retry_sequence_index_);
int next = 0;
+
if (!retry_sequence_seconds_.empty() &&
retry_sequence_index_ < retry_sequence_seconds_.size()) {
- next = retry_sequence_seconds_[retry_sequence_index_];
- ++retry_sequence_index_;
+ next = retry_sequence_seconds_[retry_sequence_index_] *
+ date_time::MILLISECONDS_IN_SECOND;
}
return next;
}
@@ -1816,10 +1859,15 @@ void PolicyManagerImpl::RefreshRetrySequence() {
cache_->SecondsBetweenRetries(retry_sequence_seconds_);
}
-void PolicyManagerImpl::ResetRetrySequence() {
+void PolicyManagerImpl::ResetRetrySequence(
+ const ResetRetryCountType reset_type) {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock auto_lock(retry_sequence_lock_);
retry_sequence_index_ = 0;
- update_status_manager_.OnResetRetrySequence();
+ is_ptu_in_progress_ = false;
+ if (ResetRetryCountType::kResetWithStatusUpdate == reset_type) {
+ update_status_manager_.OnResetRetrySequence();
+ }
}
uint32_t PolicyManagerImpl::TimeoutExchangeMSec() {
@@ -1832,6 +1880,8 @@ const std::vector<int> PolicyManagerImpl::RetrySequenceDelaysSeconds() {
}
void PolicyManagerImpl::OnExceededTimeout() {
+ LOG4CXX_AUTO_TRACE(logger_);
+
update_status_manager_.OnUpdateTimeoutOccurs();
}
@@ -1885,7 +1935,7 @@ bool PolicyManagerImpl::IsApplicationRevoked(const std::string& app_id) const {
bool PolicyManagerImpl::IsConsentNeeded(const std::string& device_id,
const std::string& app_id) {
LOG4CXX_AUTO_TRACE(logger_);
- int count = cache_->CountUnconsentedGroups(app_id, device_id);
+ const int count = cache_->CountUnconsentedGroups(app_id, device_id);
LOG4CXX_DEBUG(logger_, "There are: " << count << " unconsented groups.");
return count != 0;
}
@@ -2029,7 +2079,10 @@ StatusNotifier PolicyManagerImpl::AddApplication(
const std::string& application_id,
const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) {
LOG4CXX_AUTO_TRACE(logger_);
- DeviceConsent device_consent = GetUserConsentForDevice(device_id);
+ auto device_consent = GetUserConsentForDevice(device_id);
+ LOG4CXX_DEBUG(logger_,
+ "check_device_id: " << device_id << " check_device_consent: "
+ << device_consent);
sync_primitives::AutoLock lock(apps_registration_lock_);
if (IsNewApplication(application_id)) {
LOG4CXX_DEBUG(logger_, "Adding new application");
@@ -2067,6 +2120,7 @@ void PolicyManagerImpl::ProcessExternalConsentStatusForApp(
CalculateGroupsConsentFromExternalConsent(
groups_by_status, allowed_groups, disallowed_groups);
+ LOG4CXX_DEBUG(logger_, "check device_id: " << device_id);
UpdateAppConsentWithExternalConsent(device_id,
application_id,
allowed_groups,
@@ -2106,8 +2160,16 @@ void PolicyManagerImpl::PromoteExistedApplication(
DeviceConsent device_consent) {
// If device consent changed to allowed during application being
// disconnected, app permissions should be changed also
+ LOG4CXX_DEBUG(logger_,
+ "kDeviceAllowed == device_consent: "
+ << (kDeviceAllowed == device_consent)
+ << " device_consent: " << device_consent);
if (kDeviceAllowed == device_consent &&
cache_->IsPredataPolicy(application_id)) {
+ LOG4CXX_INFO(logger_,
+ "Setting "
+ << policy::kDefaultId
+ << " permissions for application id: " << application_id);
cache_->SetDefaultPolicy(application_id);
}
ProcessExternalConsentStatusForApp(
@@ -2173,6 +2235,11 @@ uint32_t PolicyManagerImpl::HeartBeatTimeout(const std::string& app_id) const {
}
void PolicyManagerImpl::SaveUpdateStatusRequired(bool is_update_needed) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ if (!is_update_needed) {
+ ResetRetrySequence(ResetRetryCountType::kResetInternally);
+ }
cache_->SaveUpdateRequired(is_update_needed);
}
@@ -2196,8 +2263,7 @@ void PolicyManagerImpl::SetDefaultHmiTypes(
const std::string& application_id,
const std::vector<int>& hmi_types) {
LOG4CXX_INFO(logger_, "SetDefaultHmiTypes");
- const std::string device_id =
- GetCurrentDeviceId(device_handle, application_id);
+ const auto device_id = GetCurrentDeviceId(device_handle, application_id);
ApplicationOnDevice who = {device_id, application_id};
access_remote_->SetDefaultHmiTypes(who, hmi_types);
}
diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc
index c2ee4e4bbc..3d1cae3eba 100644
--- a/src/components/policy/policy_external/src/status.cc
+++ b/src/components/policy/policy_external/src/status.cc
@@ -99,9 +99,11 @@ void policy::UpdatingStatus::ProcessEvent(policy::UpdateStatusManager* manager,
break;
case kScheduleUpdate:
case kScheduleManualUpdate:
- case kOnResetRetrySequence:
manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
+ case kOnResetRetrySequence:
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
+ break;
default:
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 b352b5ea39..050908f3a0 100644
--- a/src/components/policy/policy_external/src/update_status_manager.cc
+++ b/src/components/policy/policy_external/src/update_status_manager.cc
@@ -32,6 +32,7 @@
#include "policy/update_status_manager.h"
#include "policy/policy_listener.h"
+#include "policy/ptu_retry_handler.h"
#include "utils/logger.h"
namespace policy {
@@ -87,6 +88,14 @@ void UpdateStatusManager::OnUpdateSentOut(uint32_t update_timeout) {
void UpdateStatusManager::OnUpdateTimeoutOccurs() {
LOG4CXX_AUTO_TRACE(logger_);
+
+ auto& ptu_retry_handler = listener_->ptu_retry_handler();
+
+ if (ptu_retry_handler.IsAllowedRetryCountExceeded()) {
+ ptu_retry_handler.RetrySequenceFailed();
+ return;
+ }
+
ProcessEvent(kOnUpdateTimeout);
DCHECK(update_status_thread_delegate_);
update_status_thread_delegate_->updateTimeOut(0); // Stop Timer
diff --git a/src/components/policy/policy_external/test/update_status_manager_test.cc b/src/components/policy/policy_external/test/update_status_manager_test.cc
index f5192471cc..0577e6741d 100644
--- a/src/components/policy/policy_external/test/update_status_manager_test.cc
+++ b/src/components/policy/policy_external/test/update_status_manager_test.cc
@@ -121,6 +121,8 @@ TEST_F(UpdateStatusManagerTest,
WaitAsync waiter(count, timeout);
EXPECT_CALL(listener_, OnUpdateStatusChanged(_))
.WillRepeatedly(NotifyAsync(&waiter));
+ EXPECT_CALL(listener_, IsAllowedPTURetriesExceeded())
+ .WillRepeatedly(Return(false));
manager_->ScheduleUpdate();
manager_->OnUpdateSentOut(k_timeout_);
status_ = manager_->GetLastUpdateStatus();
@@ -131,6 +133,36 @@ TEST_F(UpdateStatusManagerTest,
EXPECT_EQ(StatusUpdateRequired, status_);
}
+TEST_F(
+ UpdateStatusManagerTest,
+ OnUpdateSentOut_WaitForTimeoutExpired_ExpectStatusUpdateNeeded_RetryExceeded) {
+ sync_primitives::Lock lock;
+ sync_primitives::AutoLock auto_lock(lock);
+ const uint32_t count = 3u;
+ const uint32_t timeout = 2u * k_timeout_;
+ WaitAsync waiter(count, timeout);
+ EXPECT_CALL(listener_, OnUpdateStatusChanged(_))
+ .WillRepeatedly(NotifyAsync(&waiter));
+ manager_->ScheduleUpdate();
+ manager_->OnUpdateSentOut(k_timeout_);
+ status_ = manager_->GetLastUpdateStatus();
+ {
+ ::testing::InSequence s;
+ EXPECT_CALL(listener_, IsAllowedPTURetriesExceeded())
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(listener_, IsAllowedPTURetriesExceeded())
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(listener_, IsAllowedPTURetriesExceeded())
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(listener_, OnPTUFinished(false));
+ }
+ EXPECT_EQ(StatusUpdatePending, status_);
+ EXPECT_TRUE(waiter.Wait(auto_lock));
+ status_ = manager_->GetLastUpdateStatus();
+ // Check
+ EXPECT_EQ(StatusUpdateRequired, status_);
+}
+
TEST_F(UpdateStatusManagerTest,
OnUpdateTimeOutOccurs_ExpectStatusUpdateNeeded) {
// Arrange
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 c14fb0e142..7acca8bdee 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
@@ -183,7 +183,7 @@ class PolicyManagerImpl : public PolicyManager {
/**
* @brief PTU is needed, for this PTS has to be formed and sent.
*/
- bool RequestPTUpdate() OVERRIDE;
+ bool RequestPTUpdate(const PTUIterationType iteration_type) OVERRIDE;
/**
* @brief Check if specified RPC for specified application
@@ -247,8 +247,10 @@ class PolicyManagerImpl : public PolicyManager {
/**
* @brief Resets retry sequence
+ * @param send_event - if true corresponding event is sent to
+ * UpdateStatusManager
*/
- void ResetRetrySequence();
+ void ResetRetrySequence(const ResetRetryCountType reset_type) OVERRIDE;
/**
* @brief Gets timeout to wait before next retry updating PT
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 2794615cb4..08ff9b4285 100644
--- a/src/components/policy/policy_regular/include/policy/policy_types.h
+++ b/src/components/policy/policy_regular/include/policy/policy_types.h
@@ -78,6 +78,10 @@ enum PolicyTableStatus {
StatusUnknown
};
+enum class PTUIterationType { DefaultIteration = 0, RetryIteration };
+
+enum class ResetRetryCountType { kResetWithStatusUpdate = 0, kResetInternally };
+
typedef rpc::Optional<rpc::Boolean> EncryptionRequired;
// Code generator uses String class name, so this typedef was renamed to PTSring
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 6871a5c416..5b9856193e 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -316,6 +316,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
FilterPolicyTable(pt_update->policy_table);
if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
wrong_ptu_update_received_ = true;
+ ResetRetrySequence(ResetRetryCountType::kResetInternally);
update_status_manager_.OnWrongUpdateReceived();
return false;
}
@@ -519,7 +520,7 @@ void PolicyManagerImpl::GetUpdateUrls(const uint32_t service_type,
cache_->GetUpdateUrls(service_type, out_end_points);
}
-bool PolicyManagerImpl::RequestPTUpdate() {
+bool PolicyManagerImpl::RequestPTUpdate(const PTUIterationType iteration_type) {
LOG4CXX_AUTO_TRACE(logger_);
std::shared_ptr<policy_table::Table> policy_table_snapshot =
cache_->GenerateSnapshot();
@@ -538,7 +539,7 @@ bool PolicyManagerImpl::RequestPTUpdate() {
BinaryMessage update(message_string.begin(), message_string.end());
- listener_->OnSnapshotCreated(update);
+ listener_->OnSnapshotCreated(update, iteration_type);
return true;
}
@@ -580,7 +581,8 @@ void PolicyManagerImpl::StartPTExchange() {
}
if (update_status_manager_.IsUpdateRequired()) {
- if (RequestPTUpdate() && !timer_retry_sequence_.is_running()) {
+ if (RequestPTUpdate(PTUIterationType::DefaultIteration) &&
+ !timer_retry_sequence_.is_running()) {
// Start retry sequency
const uint32_t timeout_msec = NextRetryTimeout();
@@ -1192,6 +1194,7 @@ std::string PolicyManagerImpl::GetPolicyTableStatus() const {
}
uint32_t PolicyManagerImpl::NextRetryTimeout() {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock auto_lock(retry_sequence_lock_);
LOG4CXX_DEBUG(logger_, "Index: " << retry_sequence_index_);
uint32_t next = 0u;
@@ -1224,10 +1227,14 @@ void PolicyManagerImpl::RefreshRetrySequence() {
cache_->SecondsBetweenRetries(retry_sequence_seconds_);
}
-void PolicyManagerImpl::ResetRetrySequence() {
+void PolicyManagerImpl::ResetRetrySequence(
+ const ResetRetryCountType reset_type) {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock auto_lock(retry_sequence_lock_);
retry_sequence_index_ = 0;
- update_status_manager_.OnResetRetrySequence();
+ if (ResetRetryCountType::kResetWithStatusUpdate == reset_type) {
+ update_status_manager_.OnResetRetrySequence();
+ }
}
uint32_t PolicyManagerImpl::TimeoutExchangeMSec() {
@@ -1496,6 +1503,11 @@ uint32_t PolicyManagerImpl::HeartBeatTimeout(const std::string& app_id) const {
}
void PolicyManagerImpl::SaveUpdateStatusRequired(bool is_update_needed) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ if (!is_update_needed) {
+ ResetRetrySequence(ResetRetryCountType::kResetInternally);
+ }
cache_->SaveUpdateRequired(is_update_needed);
}
@@ -1513,6 +1525,11 @@ void PolicyManagerImpl::StartRetrySequence() {
if (is_exceeded_retries_count) {
LOG4CXX_WARN(logger_, "Exceeded allowed PTU retry count");
listener_->OnPTUTimeOut();
+ ResetRetrySequence(ResetRetryCountType::kResetWithStatusUpdate);
+ if (timer_retry_sequence_.is_running()) {
+ timer_retry_sequence_.Stop();
+ }
+ return;
}
update_status_manager_.OnUpdateTimeoutOccurs();
@@ -1526,7 +1543,7 @@ void PolicyManagerImpl::StartRetrySequence() {
return;
}
- RequestPTUpdate();
+ RequestPTUpdate(PTUIterationType::RetryIteration);
timer_retry_sequence_.Start(timeout_msec, timer::kPeriodic);
}
diff --git a/src/components/policy/policy_regular/src/status.cc b/src/components/policy/policy_regular/src/status.cc
index 00a6a95af3..114ecb9f97 100644
--- a/src/components/policy/policy_regular/src/status.cc
+++ b/src/components/policy/policy_regular/src/status.cc
@@ -101,9 +101,11 @@ void policy::UpdatingStatus::ProcessEvent(
manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
case kScheduleUpdate:
- case kOnResetRetrySequence:
manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
+ case kOnResetRetrySequence:
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
+ break;
default:
break;
}
diff --git a/src/components/protocol_handler/docs/assets/PTU_for_EXTERNAL_PROPRIETARY.png b/src/components/protocol_handler/docs/assets/PTU_for_EXTERNAL_PROPRIETARY.png
index 19173570aa..5962a1f08b 100644
--- a/src/components/protocol_handler/docs/assets/PTU_for_EXTERNAL_PROPRIETARY.png
+++ b/src/components/protocol_handler/docs/assets/PTU_for_EXTERNAL_PROPRIETARY.png
Binary files differ
diff --git a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
index 2c7f7de67e..5be513049d 100644
--- a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
+++ b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
@@ -90,7 +90,7 @@ class HandshakeHandler : public security_manager::SecurityManagerListener {
*/
void OnCertificateUpdateRequired() OVERRIDE;
- void OnPTUFailed() OVERRIDE;
+ bool OnPTUFailed() OVERRIDE;
#ifdef EXTERNAL_PROPRIETARY_MODE
/**
diff --git a/src/components/protocol_handler/src/handshake_handler.cc b/src/components/protocol_handler/src/handshake_handler.cc
index 2109e637a4..405715fe1b 100644
--- a/src/components/protocol_handler/src/handshake_handler.cc
+++ b/src/components/protocol_handler/src/handshake_handler.cc
@@ -103,11 +103,13 @@ bool HandshakeHandler::OnGetSystemTimeFailed() {
return true;
}
-void HandshakeHandler::OnPTUFailed() {
+bool HandshakeHandler::OnPTUFailed() {
LOG4CXX_AUTO_TRACE(logger_);
if (payload_) {
ProcessFailedHandshake(*payload_, ServiceStatus::PTU_FAILED);
}
+
+ return true;
}
bool HandshakeHandler::OnHandshakeDone(
diff --git a/src/components/security_manager/src/security_manager_impl.cc b/src/components/security_manager/src/security_manager_impl.cc
index 488b4745be..41e2b07a03 100644
--- a/src/components/security_manager/src/security_manager_impl.cc
+++ b/src/components/security_manager/src/security_manager_impl.cc
@@ -415,9 +415,21 @@ void SecurityManagerImpl::ProcessFailedPTU() {
LOG4CXX_DEBUG(logger_, "listeners arrays IS EMPTY!");
return;
}
- std::for_each(listeners_.begin(),
- listeners_.end(),
- std::mem_fun(&SecurityManagerListener::OnPTUFailed));
+
+ std::list<SecurityManagerListener*> listeners_to_remove;
+ for (auto listener : listeners_) {
+ if (listener->OnPTUFailed()) {
+ listeners_to_remove.push_back(listener);
+ }
+ }
+
+ for (auto& listener : listeners_to_remove) {
+ auto it = std::find(listeners_.begin(), listeners_.end(), listener);
+ DCHECK(it != listeners_.end());
+ LOG4CXX_DEBUG(logger_, "Destroying listener: " << *it);
+ delete (*it);
+ listeners_.erase(it);
+ }
}
#ifdef EXTERNAL_PROPRIETARY_MODE